2014-09-21 83 views
0

我想通過UnifiedPushServer in Node.js發送消息給我的android設備。無法通過UnifiedPushServer推送消息Node.js

我想:

var agSender = require("unifiedpush-node-sender").AeroGear, 
    url = "http://192.168.1.9:8080/ag-push",message="Hello"; 


settings = { 
    applicationID: "8f39bc13-acb7-4d34-baa1-c2343f8ebff4", 
    masterSecret: "2a1a901a-34f7-40c9-b6d0-50129c4794ae"  
}; 

agSender.Sender(url).send(message, settings).on("success", function(response) { 
    console.log("success called", response); 
}).on("error",function(error){ 
    console.log(error); 
}); 

並開始運行,我得到這個代碼:

D:\node>node server.js 

events.js:74 
     throw TypeError('Uncaught, unspecified "error" event.'); 
      ^
TypeError: Uncaught, unspecified "error" event. 
    at TypeError (<anonymous>) 
    at emit (events.js:74:15) 
    at doEvent (D:\node\node_modules\unifiedpush-node-sender\lib\unifiedpush-nod 
e-sender.js:25:14) 
    at ClientRequest.<anonymous> (D:\node\node_modules\unifiedpush-node-sender\l 
ib\unifiedpush-node-sender.js:44:25) 
    at ClientRequest.g (events.js:180:16) 
    at ClientRequest.emit (events.js:95:17) 
    at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1692:21) 
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23 
) 
    at Socket.socketOnData [as ondata] (http.js:1587:20) 
    at TCP.onread (net.js:527:27) 

可能是什麼問題呢?

回答

0

您不需要再.AeroGear這裏

var agSender = require("unifiedpush-node-sender").AeroGear

+0

的問題是與消息格式。需要JSON {} – writeToBhuwan 2014-09-22 17:27:00

+0

感謝您的幫助!在我的代碼中也修復了.Aerogear :) – writeToBhuwan 2014-09-22 17:27:36