--
參考資源
- Mastering Firebase Push Notifications with Python: Elevate Your App’s Engagement with Firebase… | by Prabha Obulichetty | Medium
- Not sound option for messaging.Notification · Issue #158 · firebase/firebase-admin-python · GitHub
- ios - Python Firebase Admin SDK appears successful but I never receive the notification - Stack Overflow
--
Python 3 範例程式碼
相較於 PHP Google API 精簡許多,如果不需要推播提示音就把 android, apns 移除即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import firebase_admin from firebase_admin import credentials from firebase_admin import messaging # Replace with the path to your service account key JSON file server_key = 'upad12-xxxxx-xxxxx.json' cred = credentials.Certificate(server_key) firebase_admin.initialize_app(cred) def send_push_notification(device_tokens, title, body): message = messaging.Message( notification=messaging.Notification( title=title, body=body ), token=device_tokens, android=messaging.AndroidConfig(priority='high', notification=messaging.AndroidNotification(sound='default'), ), apns=messaging.APNSConfig(payload=messaging.APNSPayload(aps=messaging.Aps(sound='default'), ), ) ) response = messaging.send(message) print("Successfully sent notification:", response) device_tokens = 'token' # Notification details title = 'aaaa1' body = 'bbbb2' # Send push notification send_push_notification(device_tokens, title, body) |
--
221 total views, 3 views today