簡體   English   中英

使用 Firebase 雲消息傳遞、Python API 發送通知失敗

[英]Failing sending notifications using firebase cloud messaging, Python API

閱讀 Firebase 文檔,我編寫了該 Python 腳本,以便向我的 Android 應用程序發送一些通知。

import firebase_admin 
from firebase_admin import credentials, messaging

#USING ENV VARIABLE: GOOGLE_APPLICATION_CREDENTIALS 
app = firebase_admin.initialize_app()

topic = 'uat-test' 
notification = messaging.Notification(title="Title", body="Body")

# See documentation on defining a message payload. 
message = messaging.Message(
    notification=notification,
    topic=topic, )

# Send a message to the devices subscribed to the provided topic. 
messaging.send(message)

# Response is a message ID string. 
print('Successfully sent message:', message)

身份驗證信息存儲在 GOOGLE_APPLICATION_CREDENTIALS 環境變量中,該變量指向我從 firebase.google.com 下載的私鑰 json 文件。

即使我得到消息 ID 作為輸出並且沒有顯示錯誤消息,我也沒有在手機上看到任何通知。 僅當我通過網絡應用程序 (firebase.google.com) 使用 Firebase 控制台手動發送通知時,我才能成功收到通知,但我需要自動化該過程。 手動調度時出現的通知告訴我我的應用程序成功訂閱了該主題,但我不明白為什么 Python API 不起作用。 我不認為是環境問題,因為我也嘗試過 Node API 並且得到了相同的結果。 任何人都有一些線索? 我覺得我錯過了一些東西。 我從我的電腦上運行腳本,我不知道它是否可以計算。

我找到了一種顯示通知的方法。 事實證明,由於我使用 Flutter Framework 進行開發,因此 Android 應用程序只能通過舊版應用程序服務器協議處理通知: Firebase 文檔舊版協議

使用該方法最終顯示通知。 不知道iOS會不會有同樣的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM