Skip to content

Instantly share code, notes, and snippets.

@StefMa
Last active August 29, 2015 14:24
Show Gist options
  • Save StefMa/e0577897af21cf611ac3 to your computer and use it in GitHub Desktop.
Save StefMa/e0577897af21cf611ac3 to your computer and use it in GitHub Desktop.
Example of GCM-Server in Python
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