2017-01-03 98 views
0

我試圖使用POST調用GCM通知。 我使用的代碼是:節點獲取JSON_PARSING_ERROR

var jsonbody={"to": "/topics/global", 
       "data": { 
       "title": "TestTitle", 
       "is_background": false, 
       "message": "Testmessage", 
       "image": "", 
       "payload": { 
        "team": "India", 
        "score": "5.6"   }, 
       "timestamp": "2016-12-13 16:32:05" 

       } 
      }; 

    var request = require('request'); 
    request.post({ 
    headers: {'content-type': 'application/json', 
    Authorization:'key=(my key)'}, 
    url: 'https://fcm.googleapis.com/fcm/send', 
    BODY: jsonbody 
    }, function (error, response, body) { 
    if (error) { 

    console.log('failure ' + error); 

    } else { 

    console.log('success '+response + 'and ' +body); 

    } 
    }); 

我得到的錯誤爲:

success [object Object]and JSON_PARSING_ERROR: Unexpected token END OF FILE at position 0.

回答

0

我其實是失去了一些東西:

body: JSON.stringify(jsonbody) 

,其餘全部是正確的。