簡體   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