Tuesday, 14 April 2015

parse push notification by javascript/nodejs

First, there are two ways to push notification:

1. by the RESTful api
2. by the parse javascript api.

I will introduce the second one in the post only (for nodejs only, if you want to do it by angular you should use bower instead of npm to install.):

1, install parse package into nodejs:  (http://blog.parse.com/2012/10/11/the-javascript-sdk-in-node-js/)

npm install parse

2, The code is very simple:

exports.xxxxxxx = function(req, res) {
var Parse = require('parse').Parse;
Parse.initialize("your app key", "your javascript key");

 channels: [ "Giants", "test" ],
 data: {
   alert: "The Giants won against the Mets 2-3."
}, {
 success: function() {
  console.log("send okkkkkk");
 error: function(error) {
  console.log("send error" + error);
   // Handle error

Where is your keys:

3. Error:

You may got this error:

{"code":115,"message":"Client-initiated push isn't enabled."}

solution:   (https://www.parse.com/questions/push-notification-is-failed-although-they-were-sent-from-cloudcode)

 you should enable client push by:

No comments:

Post a comment