Firebase云消息传递NodeJS PROJECT_NOT_PERMITTED

jvlzgdj9  于 2023-05-28  发布在  Node.js
关注(0)|答案(1)|浏览(197)

我正在尝试使用firebase-admin从我的nodejs应用程序向我的android应用程序发送推送通知
我按照如下的指示去做

import firebaseAdmin from 'firebase-admin';

import serviceAccount from '../../common/constants/pushKey.json';
firebaseAdmin.initializeApp({
  credential: firebaseAdmin.credential.cert(serviceAccount),
});

而pushKey是从
项目设置->服务帐户-> firebase adminsdk->生成新私钥
但是当调用
firebaseAdmin.messaging().sendToDevice(token, payload)
我得到以下错误

<TITLE>PROJECT_NOT_PERMITTED</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>PROJECT_NOT_PERMITTED</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
". Status code: 401.
    at FirebaseMessagingError.<anonymous> (/Users/chris/Documents/ZebedeeApps/booty/node_modules/core-js/internals/wrap-error-constructor-with-cause.js:37:62)
    at FirebaseMessagingError.Error (/Users/chris/Documents/ZebedeeApps/booty/node_modules/core-js/modules/es.error.cause.js:28:43)
    at FirebaseMessagingError.FirebaseError [as constructor] (/Users/chris/Documents/ZebedeeApps/booty/node_modules/firebase-admin/lib/utils/error.js:44:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/Users/chris/Documents/ZebedeeApps/booty/node_modules/firebase-admin/lib/utils/error.js:90:28)
    at new FirebaseMessagingError (/Users/chris/Documents/ZebedeeApps/booty/node_modules/firebase-admin/lib/utils/error.js:279:16)
    at Object.createFirebaseError (/Users/chris/Documents/ZebedeeApps/booty/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:57:12)
    at /Users/chris/Documents/ZebedeeApps/booty/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:79:51
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  errorInfo: {
    code: 'messaging/authentication-error',
    message: 'An error occurred when trying to authenticate to the FCM servers. Make sure the credential used to authenticate this SDK has the proper permissions. See https://firebase.google.com/docs/admin/setup for setup instructions. Raw server response: "<HTML>\n' +
      '<HEAD>\n' +
      '<TITLE>PROJECT_NOT_PERMITTED</TITLE>\n' +
      '</HEAD>\n' +
      '<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n' +
      '<H1>PROJECT_NOT_PERMITTED</H1>\n' +
      '<H2>Error 401</H2>\n' +
      '</BODY>\n' +
      '</HTML>\n' +
      '". Status code: 401.'
  },
  codePrefix: 'messaging'
}

有什么想法吗

相关问题