Last active
August 29, 2015 14:24
-
-
Save StefMa/e0577897af21cf611ac3 to your computer and use it in GitHub Desktop.
Example of GCM-Server in Python
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
try: | |
# Specify the url | |
url = 'https://android.googleapis.com/gcm/send' | |
# Setup the data to send | |
data = json.dumps({ "registration_ids" : [""+ USER_GCM_IDS +""], "data" : { "question" : data.question, "questionDetail" : data.questionDetail, "answerFormat" : data.answerFormat, "dateend" : str(data.dateend), "image" : data.image} }) | |
# Add header | |
headers = {'Content-Type' : 'application/json', 'Authorization' : 'key=API_ACCESS_KEY'} | |
# This packages the request (it doesn't make it) | |
request = urllib2.Request(url, data, headers) | |
# Sends the request and catches the response | |
response = urllib2.urlopen(request) | |
# Extracts the response | |
html = response.read() | |
# Print it out | |
self.response.out.write(html) | |
except AttributeError: | |
# Error output | |
self.response.out.write("Error by Sending") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment