正在获取请求具有无效的身份验证凭据错误FCM

Nij*_*K J 2 firebase postman firebase-cloud-messaging

我正在尝试测试邮递员的网络推送通知

我的应用程序ID是thepostman-2018,因此https://fcm.googleapis.com/v1/projects/thepostman-2018/messages:send 尽管我已设置身份验证标头并传递了我的服务器密钥,但我仍向url 事件发送了请求请求

我得到这个回应

{
    "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"
    }
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Jen*_*son 5

FCM v1请求不使用Firebase控制台中的API密钥来授权请求​​。取而代之的是,他们使用通过从Firebase控制台下载的服务帐户密钥进行身份验证来检索的凭据。例如,这是使用Node.js生成令牌的方式:

 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);
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参见指南