Created
July 8, 2016 10:46
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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