Node.js - null但已授权

时间:2014-03-11 04:48:59

标签: android node.js cordova

当我为推送通知尝试触发节点脚本时,我收到了此Unauthorized null消息。

enter image description here

我使用此示例代码进行推送通知。

https://github.com/hollyschinsky/PushNotificationSample30/

请参阅本网站以供参考。

http://devgirl.org/2013/07/17/tutorial-implement-push-notifications-in-your-phonegap-application/

我已经检查了这个解决方案,但它仍然无法正常工作。为什么呢?

node.js returns null push messages

在我插入正确的API密钥后,我们获得了授权但无效。

2 个答案:

答案 0 :(得分:2)

实际上" null"在这种情况下意味着它是成功的。问题是当您在本地环境中运行应用程序并且设备已连接到wifi时。在某种情况下,防火墙会阻止来自GCM使用的传出连接端口的流量(5228,5229,5230)。

您可以参考该网站作为参考
http://developer.android.com/google/gcm/http.html

答案 1 :(得分:0)

看起来您还没有注册api密钥。这是来自您发布的网址。

 var gcm = require('node-gcm');
var message = new gcm.Message();

//API Server Key
var sender = new gcm.Sender('AIzaSyCDx8v9R0fMsAsjoAffF-P3FCFWXlvwLhg');
var registrationIds = [];

// Value the payload data to send...
message.addData('message',"\u270C Peace, Love \u2764 and PhoneGap \u2706!");
message.addData('title','Push Notification Sample' );
message.addData('msgcnt','3'); // Shows up in the notification in the status bar
message.addData('soundname','beep.wav'); //Sound to play upon notification receipt - put in the www folder in app
//message.collapseKey = 'demo';
//message.delayWhileIdle = true; //Default is false
message.timeToLive = 3000;// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.

// At least one reg id required
registrationIds.push('APA91bwu-47V0L7xB55zoVd47zOJahUgBFFuxDiUBjLAUdpuWwEcLd3FvbcNTPKTSnDZwjN384qTyfWW2KAJJW7ArZ-QVPExnxWK91Pc-uTzFdFaJ3URK470WmTl5R1zL0Vloru1B-AfHO6QFFg47O4Cnv6yBOWEFcvZlHDBY8YaDc4UeKUe7ao');

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