Skip to content

Instantly share code, notes, and snippets.

@suhanlee
Last active February 26, 2016 06:35
Show Gist options
  • Save suhanlee/5154c2551354cca1a249 to your computer and use it in GitHub Desktop.
Save suhanlee/5154c2551354cca1a249 to your computer and use it in GitHub Desktop.
Simple GCM Send Script
#!/usr/bin/env python
import os
API_KEY='API_KEY'
DEVICE_TOKENS = 'DEVICE_TOKEN'
MESSAGES = "messages"
command_string = "curl https://android.googleapis.com/gcm/send" \
" -H 'Content-Type: application/json'" \
" -H 'Authorization: key=" + API_KEY + "'" \
" -d '{\"registration_ids\": [\"" + DEVICE_TOKENS + "\"], \"data\": { \"message\": \"" + MESSAGES + "\" }}'"
print(command_string)
os.system(command_string)
import requests
API_KEY='API_KEY'
DEVICE_TOKENS='DEVICE_TOKEN'
MESSAGES='messages'
headers = {
"Content-Type": "application/json",
"Authorization": "key=" + API_KEY,
}
payload = {
"registration_ids": [ DEVICE_TOKENS ],
"data": { "message": MESSAGES }
}
r = requests.post('https://android.googleapis.com/gcm/send', headers=headers, json=payload)
print(r.status_code)
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment