我正在尝试使用Postman通过Firebase Cloud Messaging发送测试通知。我将发送POST请求到以下URL:
https://fcm.googleapis.com/v1/projects/[my project name]/messages:send
在Postman中,授权选项卡设置为"无授权",我的标头选项卡如下所示。Content-Type: application/json
Authorization: Bearer [server key]
在我的Firebase项目的“设置”区域的“云消息传递”选项卡中,[server key] 是新生成的服务器密钥。我一直在收到此错误响应。"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
根据我所了解的,我正在使用正确的令牌,但似乎谷歌并不认同。为了避免出现此错误,我应该如何设置Authorization头?
https://fcm.googleapis.com/fcm/send
。我不太愿意使用遗留API,而不是需要用户oAuth令牌的V2 API。虽然我正在使用Firebase身份验证,但用户的令牌并不容易获得和保持最新(尽管这看起来很傻)。感谢您的指引。 - sonicblis