09:46:05 # Life Sending GCM send message from nodejs. I wanted to send a message from emacs, but it seemed to be relatively difficult to send HTTPS POST request from emacs, so I just decided to use handy nodejs. The attached 'data' is attached to intent as extra, so it can be extracted by intent.getExtras.getString("message") in IntentService#onHandleIntent()
var https = require('https'); message = { // Registration IDs come from application after registration. registration_ids: [ // From XXX 'xxxxx', ], data: { // This is the actual message message: 'hello world' } } var options = { hostname: 'android.googleapis.com', port: 443, path: '/gcm/send', method: 'POST', headers: { // Secret from dashboard. 'Authorization': 'key=xxx', 'Content-Type': 'application/json'} }; req = https.request(options, function(res) { console.log("Got response: " + res.statusCode); res.on('data', function(d) { process.stdout.write(d); }); }).on('error', function(e) { console.log("Got error: " + e.message); }); req.write(JSON.stringify(message)); req.end();
$Id: dancer-diary.el,v 1.94 2009/10/21 14:02:48 dancer Exp $