Skip to content

Instantly share code, notes, and snippets.

@t0mdicks0n
Created October 9, 2018 19:23
Show Gist options
  • Save t0mdicks0n/51c04eeed676fc4820ed8cbc0c9d8d5b to your computer and use it in GitHub Desktop.
Save t0mdicks0n/51c04eeed676fc4820ed8cbc0c9d8d5b to your computer and use it in GitHub Desktop.
A short gist on how to post a push notifications on Android with Python and requests. Much easier to fiddle with this intuitive code when exploring FCM compared to for example Postman.
import requests
import json
body = {
"data":{
"title":"Panprices",
"body":"Go online and shop!",
"url":"https://www.panprices.com"
},
"notification": {
"title":"Panprices",
"body":"Has now a bunch of new offers",
"content_available": "true"
},
"to":"<add a token to your user here>"
}
headers = {"Content-Type":"application/json", "Authorization": "key=<your server key here>"}
try :
res = requests.post(
'https://fcm.googleapis.com/fcm/send',
data=json.dumps(body),
headers=headers
)
except Exception as e:
print("There was an error: ", e)
finally :
print res.status_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment