Node.js – null但授权

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

在这里输入图像描述

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

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

请参考本网站以供参考。

Tutorial: Implement Push Notifications in your PhoneGap Application

我已经检查过这个解决scheme,但是仍然没有工作。 为什么?

node.js返回null推送消息

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

其实“空”意味着它是成功的。 问题是当你在本地环境中运行你的应用程序,并且设备连接到wifi。 防火墙阻塞来自GCM(5228,5229,5230)使用的出站连接端口的stream量。

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

看起来你还没有注册一个API密钥。 这是从你张贴的url。

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); });