簡體   English   中英

通過 POST 發送推送通知需要哪個令牌

[英]Which token is needed to send push notifications through POST

我正在嘗試設置可以使用 Firebase 發送推送通知的 REST API 服務器。 谷歌文檔說這是一個有效的 POST 請求,作為開始:

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
  "message":{
    "topic" : "foo-bar",
    "notification" : {
      "body" : "This is a Firebase Cloud Messaging Topic Message!",
      "title" : "FCM Message",
      }
   }
}

但是,我無法弄清楚這里應該使用哪個授權承載。 firebase 控制台上有很多,我已經嘗試了每一個,都沒有工作。 它們都導致 401 響應。

我在哪里可以找到此請求的預期承載?

謝謝 !

我發現使用舊協議發送推送通知更容易。 我們只需要可以在 Firebase 控制台中找到的服務器密鑰。

Firebase 控制台 > 項目設置 > 雲消息傳遞 > 服務器密鑰

HTTP 請求如下所示:

curl -X POST -H "Authorization: key=<your_server_key>" -H "Content-Type: application/json" -d '{
  "notification": {
    "body" : "This is a Firebase Cloud Messaging Topic Message!",
    "title" : "FCM Message",
  },
  "to": "/topics/<topic_name>"
}' "https://fcm.googleapis.com/fcm/send"

檢查服務器參考以獲取其他用於服務器實現的 API。

因此,首先 go 到Google Cloud Console並選擇 APIs&Services->Credentials。 從那里點擊+Create Credentials->OAuth Client ID (界面一直在變化,所以試着找到這個選項)。 然后,只需選擇添加密鑰,它就會為您提供 json 文件。

收到 json 文件后,您可以嘗試本指南中給出的內容: https://firebase.google.com/docs/cloud-messaging/auth-server

如果您想從Postman發送請求,那么您可以嘗試https://developers.google.com/oauthplayground Register there with your google account and from available services select Firebase Cloud Messaging API v1 -> https://www.googleapis.com/auth/firebase.messaging . 在第二步中,按 Exchange 授權碼獲取令牌。 最后,您將在那里獲得訪問和刷新令牌

暫無
暫無

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

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