我应该使用什么Bearer令牌进行Firebase Cloud Messaging测试? [英] What Bearer token should I be using for Firebase Cloud Messaging testing?
问题描述
我正在尝试通过Postman使用Firebase Cloud Messaging发送测试通知.我正在对此URL进行POST
I am trying to send a test notification using Firebase Cloud Messaging via Postman. I'm doing a POST to this url
https://fcm.googleapis.com/v1/projects/[my project name]/messages:send
邮递员中的授权"标签设置为无身份验证",我的标题"标签看起来像这样
The Authorization tab in Postman is set to No Auth and my Headers tab looks like this
Content-Type: application/json
Authorization: Bearer [server key]
[服务器密钥]是Firebase项目设置"区域中云消息"选项卡中的新生成的服务器密钥.我不断收到此错误消息.
[server key] is a newly generated server key in the 'Cloud Messaging' tab of my Firebase project's 'Settings' area. I keep getting this error in response.
"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"
}
根据我能找到的所有内容,我使用的是正确的令牌,但Google似乎不同意.我应该发送什么作为Authorization标头来克服此错误?
Based on everything I can find, I'm using the right token, but it seems Google disagrees. What should I be sending as the Authorization header to get past this error?
推荐答案
您必须在Postman中生成新的访问令牌.
You have to generate new access token in Postman.
首先,请确保您已在Google Developer Console中启用了FCM API. 比转到Google Developer Console-> APIs&服务->凭证.查看"OAuth 2.0客户端ID"部分.列表中至少应有一项.将其下载为json文件.
First, ensure you have enabled FCM API in Google Developer Console. Than go to Google Developer Console -> APIs & Services -> Credentials. Look at "OAuth 2.0 client IDs" section. There should be at least one item in list. Download it as json file.
在邮递员中打开授权"选项卡,选择类型" ="OAuth 2.0",然后单击获取新访问令牌".出现对话框.
In Postman open "Authorization" tab, select Type = "OAuth 2.0" than click "Get New Access Token". Dialog appears.
字段:
令牌名称-输入您想要的
Token Name - type what you want
授予类型=授权代码
下载的json中的回调URL = redirect_uris
Callback URL = redirect_uris from downloaded json
验证URL = auth_uri
Auth URL = auth_uri
访问令牌URL = token_uri
Access Token URL = token_uri
客户ID = client_id
Client ID = client_id
Client Secret = client_secret
Client Secret = client_secret
Scope =" https://www.googleapis.com/auth/firebase.messaging"
状态-留空
客户端身份验证=默认,作为基本身份验证标头发送
Client Authentication = default, Send As Basic Auth Header
单击请求令牌",仅此而已.
Click "Request Token" and that's it.
这篇关于我应该使用什么Bearer令牌进行Firebase Cloud Messaging测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!