android - Google 的 Firebase 下游消息的 http post 请求的 `Authorization` 部分是什么?

标签 android push-notification firebase google-cloud-messaging firebase-cloud-messaging

我想尝试使用谷歌的 FCM 消息服务发送消息,正如文档所述,http 请求应该是这样的:

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}

我的问题是我不知道 Authorization 的值应该是什么,当我删除此 header 并发出请求时,我收到错误 401:Unauthorized。我认为这一定是某种 api key 或其他东西,但我在我的项目中找不到它。谁能帮帮我?

PS:出于测试目的,我目前正在使用 this site向我的设备发送消息

最佳答案

根据About Firebase Cloud Messaging Server文档:

Authentication

To send a message, the app server issues a POST request. For example:

https://fcm.googleapis.com/fcm/send

A message request consists of two parts: the HTTP header and the HTTP body.

The HTTP header must contain the following headers:

  • Authorization: key=YOUR_SERVER_KEY

确保这是 server 键,其值在您的 Firebase 项目控制台中的 Project Settings> Cloud Messaging 下可用。 FCM 拒绝客户端 key 或任何其他 key 。

  • Content-Type: application/json for JSON; application/x-www-form-urlencoded;charset=UTF-8 for plain text.

     If Content-Type is omitted, the format is assumed to be plain text.
    

更新 (2016/11/16)

也许您应该考虑使用 FCM token 而不是服务器 key 作为以下屏幕截图中的注释

enter image description here


更新 (2016/12/08)

Firebase 已将服务器 key 升级到新版本,并建议您升级到最新版本。请看下面的截图:

enter image description here

关于android - Google 的 Firebase 下游消息的 http post 请求的 `Authorization` 部分是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37673205/

相关文章:

java - 如何在没有NDK的情况下在Android中处理原始相机数据

android - 从 ListView 中删除项目

ios - 应用程序角标(Badge)不显示解析推送通知

android - 带有图像的可扩展字符串不适用于推送通知

java - 如何将 long 或 double int 数据类型转换为 Ffirebase dataSnapshot 中的 String

ios - Xcode 11 中的构建/存档版本无限期挂起

android - 迭代 ListView 项并修改 subview

android - Firebase,无法查询 token ,并且未调用 “onTokenRefresh()”

Angular2 - 什么是好的 'dist' 文件夹大小?

android - 在 viewPager android 中使用箭头进行导航?我尝试了不同的例子但没有成功