Skip to content

Commit eea2b99

Browse files
authored
Merge pull request #359 from saranglakare/patch-1
Update README.md
2 parents d18ea23 + bce2b2f commit eea2b99

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,18 @@ proxy_dict = {
7272
}
7373
fcm = FCMNotification(service_account_file="<service-account-json-path>", project_id="<project-id>", proxy_dict=proxy_dict)
7474

75+
# OR using credentials from environment variable
76+
# Often you would save service account json in evironment variable
77+
# Assuming GCP_CREDENTIALS contains the data (TIP: use "export GCP_CREDENTIALS=$(filename.json)" to quickly load the json)
78+
79+
from google.oauth2 import service_account
80+
gcp_json_credentials_dict = json.loads(os.getenv('GCP_CREDENTIALS', None))
81+
credentials = service_account.Credentials.from_service_account_info(gcp_json_credentials_dict, scopes=['https://www.googleapis.com/auth/firebase.messaging'])
82+
fcm = FCMNotification(service_account_file=None, credentials=credentials, project_id="<project-id>")
83+
7584
# Your service account file can be gotten from: https://console.firebase.google.com/u/0/project/_/settings/serviceaccounts/adminsdk
7685

86+
# Now you are ready to send notification
7787
fcm_token = "<fcm token>"
7888
notification_title = "Uber update"
7989
notification_body = "Hi John, your order is on the way!"
@@ -106,6 +116,15 @@ result = fcm.notify(fcm_token=fcm_token, notification_body=notification_body, da
106116
# To a single device
107117
result = fcm.notify(fcm_token=fcm_token, data_payload=data_payload)
108118

119+
# Only string key and values are accepted. booleans, nested dicts are not supported
120+
# To send nested dict, use something like
121+
data_payload = {
122+
"foo": "bar",
123+
"data": json.dumps(data).
124+
}
125+
# For more info on format see https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#Message
126+
# and https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json
127+
109128
# Use notification messages when you want FCM to handle displaying a notification on your app's behalf.
110129
# Use data messages when you just want to process the messages only in your app.
111130
# PyFCM can send a message including both notification and data payloads.

0 commit comments

Comments
 (0)