Place the secret key (json) of the Firebase service account, which is generated in the Firebase Console project, into this directory.
$ cp path/to/serviceAccountKey.json sample-app-firebase-adminsdk-foobar.json
This program ues the following modules:
- argparse
- json
- requests
- oauth2client
If the required modules are not installed, please install them using the command below:
$ pip install argparse json requests oauth2client
Ensure you have obtained the device token of the desired recipient device.
Send a push notification by specifying the target device's token using the -d option.
$ python send_test.py -d d9pCrwUARmCyWDRjumG2SS:APA91xxxx
=== Request ===
Request message: {
"message": {
"token": "d9pCrwUARmCyWDRjumG2SS:APA91xxxxx",
"notification": {
"title": "Test Notification",
"body": "This is a sample notification"
}
}
}
=== Response ===
Response status code: 200
Response content: {
"name": "projects/sample-app/messages/0:1692853925636648%d2dadecfd2dadecf"
}
-d DEVICE_TOKEN, --device-token DEVICE_TOKEN
: Specify the device token.-p PRIVATE_KEY_JSON_FILE, --private-key-json-file PRIVATE_KEY_JSON_FILE
: Specify the secret key of the Firebase service account.-m MESSAGE_JSON, --message-json MESSAGE_JSON
: Specify the json file of the push notification message to be sent.-t TITLE, --title TITLE
: Specify title to set for the push notification.-b BODY, --body BODY
: Specify body to set for the push notification.-i IMAGE, --image IMAGE
: Specify image icon url to set for the push notification.--print-access-token
: Display the bearer token used for FCM HTTP v1 protocol.
- Firebase Cloud Messaging REST API
- Migrate from legacy FCM APIs to HTTP v1