09:40:41 # Life nodejs をつかってGCMメッセージを送ってみた。 JSONをHTTPS POSTで送信することができればGCMメッセージは送信できるよといわれて、 pythonで書くのめんどくさいなぁと思ったのでなんとなくnodejsで書いてみた。 僕はemacsからしか使わないので本当はnodejsに依存するんじゃなくて elisp からできるのが良い気がする。 nodejs イベントドリブンとかよりもjsonがネイティブな感じで使えるのが便利な気がする。
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 $