Skip to content

Instantly share code, notes, and snippets.

@Keshava11
Created July 8, 2016 10:46
Show Gist options
  • Save Keshava11/8715cc8880c5c275ce8a9ba9b15a0401 to your computer and use it in GitHub Desktop.
Save Keshava11/8715cc8880c5c275ce8a9ba9b15a0401 to your computer and use it in GitHub Desktop.
Python script (App Server) to post a downstream message to a particular device using FireBase Cloud Messaging.
import urllib2
import json
payload = {'data': {'name':'Robby', 'dept':'HRD'},'to':'<Token-Generated-In-Device>'}
url = 'https://fcm.googleapis.com/fcm/send'
headers = {'Content-Type': 'application/json', 'Authorization': 'key=<YourServerKey>'}
# When request body has to be plain text
# headers = {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Authorization': 'key=<YourServerKey>'}
data = json.dumps(payload)
print(data)
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
the_page = response.read()
print(the_page)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment