繁体   English   中英

Node.js-空但已授权

[英]Node.js - null but authorised

当我为推送通知尝试触发节点脚本时,收到了此未经授权的空消息。

在此处输入图片说明

我正在将此示例代码用于我的推送通知。

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

请参考此站点作为参考。

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

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

node.js返回空推送消息

插入正确的API密钥后,我们获得了授权,但为空。

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

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

看来您尚未注册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);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM