Django
GCM Pyhon Server
린기린기린
2016. 1. 21. 15:10
반응형
파이썬
import urllib2
import json
url = 'https://android.googleapis.com/gcm/send'
apiKey = 'AIza....' # 본인의 api key
myKey = "key=" + apiKey
regid = 'APA....' # 기기의 registration id
# make header
headers = {'Content-Type': 'application/json', 'Authorization': myKey}
# make json data
data = {}
data['registration_ids'] = (regid,)
data['data'] = {'data':'i love changong'}
json_dump = json.dumps(data)
# print json.dumps(data, indent=4)
req = urllib2.Request(url, json_dump, headers)
result = urllib2.urlopen(req).read()
print json.dumps(result)
반응형