简体   繁体   English

通过 POST 发送推送通知需要哪个令牌

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

I'm trying to set up a REST API server that could send push notifications using Firebase.我正在尝试设置可以使用 Firebase 发送推送通知的 REST API 服务器。 Google documentation says this is a valid POST request, as a start: 谷歌文档说这是一个有效的 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",
      }
   }
}

However, I can't figure out which Authorization bearer is expected here.但是,我无法弄清楚这里应该使用哪个授权承载。 There is a ton of them on the firebase console, and I've tried each and every one of them, none work. firebase 控制台上有很多,我已经尝试了每一个,都没有工作。 They all result in 401 response.它们都导致 401 响应。

Where can I find the expected bearer for this request?我在哪里可以找到此请求的预期承载?

Thanks !谢谢 !

I find it easier to use legacy protocols to send push notifications.我发现使用旧协议发送推送通知更容易。 We just need the Server key which can be found in the Firebase Console.我们只需要可以在 Firebase 控制台中找到的服务器密钥。

Firebase Console > Project Settings > Cloud Messaging > Server Key Firebase 控制台 > 项目设置 > 云消息传递 > 服务器密钥

HTTP request looks like this: 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"

Check Server Reference for other APIs for server implementation.检查服务器参考以获取其他用于服务器实现的 API。

So, first of all go to Google Cloud Console and choose APIs&Services->Credentials.因此,首先 go 到Google Cloud Console并选择 APIs&Services->Credentials。 From there click on +Create Credentials->OAuth Client ID (Interface changes all the time so try to find this option).从那里点击+Create Credentials->OAuth Client ID (界面一直在变化,所以试着找到这个选项)。 And then, simply choose Add Key and it will give you a json file.然后,只需选择添加密钥,它就会为您提供 json 文件。

After you receive your json file you can try what was given in this guide: https://firebase.google.com/docs/cloud-messaging/auth-server .收到 json 文件后,您可以尝试本指南中给出的内容: https://firebase.google.com/docs/cloud-messaging/auth-server

If you want to send request from Postman then you can try https://developers.google.com/oauthplayground .如果您想从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 . Register there with your google account and from available services select Firebase Cloud Messaging API v1 -> https://www.googleapis.com/auth/firebase.messaging . There in the second step press Exchange authorization code for tokens.在第二步中,按 Exchange 授权码获取令牌。 Finally, you will get your Access and Refresh Token there最后,您将在那里获得访问和刷新令牌

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 AWS Pinpoint 和 firebase 发送 iOS 推送通知? - How to send iOS push notifications through AWS Pinpoint and firebase? 通过 FCM 发送推送通知时,何时使用 iOS 设备令牌? - When to use iOS device token when sending push notifications through FCM? iOS Firebase 推送通知:如何提供 Firebase 用户的设备令牌并发送通知 - iOS Firebase Push Notifications : How To Give Firebase User's Device Token And Send Notification 我应该将 Expo 推送通知令牌视为敏感信息吗? 如果是这样,我如何以安全的方式发送通知? - Should I treat an Expo Push Notifications Token as a sensitive information? If so, how do I send notifications in a secure way? 如何从 Flutter 应用程序发送推送通知 - how to Send push notifications from Flutter app Android 的 FCM 推送通知无法直接用于令牌 - FCM push notifications for Android not working direct to token 带电容器的离子推送通知,注册并获取令牌但未收到通知 Android - Ionic push notifications with Capacitor, registering and getting token but not receiving notifications Android 有没有办法在不订阅 firebase 的主题的情况下发送推送通知? - Is there a way to send push notifications without subscribing to the topic on firebase? 如何通过 FCM 将推送通知从 arduino 发送到 android? - How to send push notifications from arduino to android via FCM? 从一个 Pinpoint 项目向多个 iOS 应用程序发送推送通知 - Send push notifications from one Pinpoint project to multiple iOS apps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM