Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ravishankarsingh1996/35e5af07ab0f7214d5ce2e930dc721dd to your computer and use it in GitHub Desktop.
Save ravishankarsingh1996/35e5af07ab0f7214d5ce2e930dc721dd to your computer and use it in GitHub Desktop.
## Install request module by running ->
# pip3 install requests
# Replace the deviceToken key with the device Token for which you want to send push notification.
# Replace serverToken key with your serverKey from Firebase Console
# Run script by ->
# python3 fcm_python.py
import requests
import json
serverToken = 'your server key here'
deviceToken = 'device token here'
headers = {
'Content-Type': 'application/json',
'Authorization': 'key=' + serverToken,
}
body = {
'notification': {'title': 'Sending push form python script',
'body': 'New Message'
},
'to':
deviceToken,
'priority': 'high',
# 'data': dataPayLoad,
}
response = requests.post("https://fcm.googleapis.com/fcm/send",headers = headers, data=json.dumps(body))
print(response.status_code)
print(response.json())
@bansalnaman15
Copy link

if I pass an array of device tokens, will it work? Thanks in advanced.

@MartinoVolcy
Copy link

How do I get a device token

@MartinoVolcy
Copy link

if I pass an array of device tokens, will it work? Thanks in advanced.

Did it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment