node.js中返回的未授权消息推送GCM

时间:2014-01-20 17:56:02

标签: android node.js google-cloud-messaging

我正在尝试通过GCM从node.js向我的Android设备发送通知。 我尝试了下面的代码来发送推送,但是当我执行节点server.js(其中server.js有代码)时,我收到了未经授权的和空消息。我只需要在客户端获取注册ID的代码(android应用程序代码)。我没有实现任何与通过GCM接收器接收相关的代码

var gcm = require('node-gcm');
var message = new gcm.Message();
var sender = new gcm.Sender('AIzaSyDMSfDB4W8q1TaN2Wp4fOsGu6HSl4INzZo');
var registrationIds = [];

message.addData('title','Hello');
message.addData('message','How are you doing?');
message.addData('msgcnt','1');
message.collapseKey = 'demo';
message.delayWhileIdle = true;
message.timeToLive = 3;

// At least one token is required - each app will register a different token
registrationIds.push('APA91bG1uXE8MSGVGVlQG6OY_XtzHkUPFA5aj-fnCcr_8mZSpe6_-fM78e1cunoMYVLskIBVRXa1Rg9RL_jMsK-azLxmhjL1Sl8IUc7VCHtT0XR_pqMMxPQHN-MZyZmV017RS8OeVytbp0WT1kDzBouOoErlg2U_AXUuww2WZUbXuE90o035QsY');

/**
 * Parameters: message-literal, registrationIds-array, No. of retries, callback-function
 */
sender.send(message, registrationIds, 4, function (result) {
    console.log(result);
});

0 个答案:

没有答案