Reputation: 973
i am new in node-gcm
,,
I attempting send data to android use node-gcm
...i don't know where i start build the project..i following this tutorial https://github.com/ToothlessGear/node-gcm but still confused...
here my code :
var gcm = require('node-gcm');
// create a message with default values
var message = new gcm.Message();
// or with object values
var message = new gcm.Message({
collapseKey: 'demo',
delayWhileIdle: true,
timeToLive: 3,
data: {
key1: 'message1'
}
});
var sender = new gcm.Sender('myApi');
var registrationIds = [];
// Optional
// add new key-value in data object
message.addDataWithKeyValue('key1','message1');
// or add a data object
message.addDataWithObject({
key1: 'message1',
});
// or with backwards compability of previous versions
message.addData('key1','testdarinodegcm');
message.collapseKey = 'demo';
message.delayWhileIdle = true;
message.timeToLive = 3;
// END Optional
// At least one required
registrationIds.push('myToken');
//registrationIds.push('regId2');
/**
* Parameters: message-literal, registrationIds-array, No. of retries, callback-function
*/
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
});
i get no error found in console...instead success but i can't receive data in android device...here message from console...
{"multicast_id":7521418564872032002,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1367890688015497%f11e78b0f9fd7ecd"}]}
why i can't receive data from node-gcm
in android device?maybe my code not complete?
Upvotes: 3
Views: 5447
Reputation: 925
Try this..
var sender = new gcm.Sender(googleApiKey);
var message = new gcm.Message();
message.addData('key1','testdarinodegcm');
message.delay_while_idle = 1;
var registrationIds = [];
registrationIds.push('APA91bHCzBP6wEfExCZlSXgf0wuOC6QEWJ-7MVFl3hgaW3Jv8FslsofGJ- qgdliyS8zjwy_W7zPaKsEZx6kbeuWdoAAexawKl1Qd6GEGV_v844n1LMRaTsWeiwI9iaLGKKq_R3scY_wuRG8uG2SZ5X9q0J67Ko3gcw');
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
});
The tutorial describes all the available options that library provides you. That does not means that you need all of them at once they are required as per situation. Try this code it will send simple message to your device.
Upvotes: 7