Skip to content

Instantly share code, notes, and snippets.

@skypanther
Created April 20, 2017 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skypanther/2cf9fdebbcb2a3d1e8f2b033b57140ed to your computer and use it in GitHub Desktop.
Save skypanther/2cf9fdebbcb2a3d1e8f2b033b57140ed to your computer and use it in GitHub Desktop.
GCM push test script
/*
Instructions
1. In the same directory where this js file exists, run `npm install gcm` (to install the required node module)
2. Get your GCM/FCM API Key from the Google APIs Console and paste it in place of "YOUR_GCM_API_KEY" below
2. You'll need your device's push token. You can get this by logging the token when your GCM-enabled app calls
the "success" callback after registering for push services. Paste it in place of "YOUR DEVICE_PUSH_TOKEN" below.
3. Run this with `node pushtest.js`
4. After a moment, you should get the push notification on your device
*/
(function (messageId, callback) {
var _GCM = require('gcm').GCM,
GCM = new _GCM('YOUR_GCM_API_KEY');
var message = {
registration_id: 'YOUR_DEVICE_PUSH_TOKEN',
'data.title': 'GCM Push Test',
'data.alert': 'Is anybody out there?',
/* 'data.sound': 'customsound.wav', // file must be in app/platform/android/res/raw */
collapse_key: messageId
};
message['data.message'] = message['data.alert'];
GCM.send(message, function (err, messageId) {
if (err) {
console.error('error!');
}
callback(0);
});
})((new Date()).getTime() + '', process.exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment