我正在尝试测试来自 postman 的网络推送通知
我的应用 ID 是 thepostman-2018,因此我正在向该网址发送发布请求
https://fcm.googleapis.com/v1/projects/thepostman-2018/messages:send
尽管我已经设置了身份验证 header 并传递了我的服务器 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"
}
}
最佳答案
FCM v1 请求不使用 Firebase 控制台中的 API key 来授权请求。相反,他们使用通过从 Firebase 控制台下载的服务帐户 key 进行身份验证而检索到的凭据。例如,这是使用 Node.js 生成 token 的方式:
function getAccessToken() {
return new Promise(function(resolve, reject) {
var key = require('./service-account.json');
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null
);
jwtClient.authorize(function(err, tokens) {
if (err) {
reject(err);
return;
}
resolve(tokens.access_token);
});
});
}
请参阅guide了解更多详情。
关于firebase - 获取请求具有无效的身份验证凭据错误 FCM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51064260/