FCM凭证失败在firebase模拟器中

发布于 2025-02-10 08:06:52 字数 3348 浏览 1 评论 0原文

我正在尝试通过Firebase Emulator IE在本地测试推送通知。我正在使用云功能并直接调用该功能。

以下是:

  1. 下载管理员密钥

  2. set google_application_credentials

➜  Desktop export GOOGLE_APPLICATION_CREDENTIALS=pearl-cef7c-4833cff1a093.json
  1. 通过firebase模拟器运行模拟器:start

  2. 尝试调用fcm函数:admin.messaging()。sendtotopic(topic,message);通过webhook。 P>

  3. 获得失败确保用于身份验证此SDK的凭据具有适当的权限。

为什么我的管理员密钥会失败?当我使用服务帐户时,我也有同样的问题!

i  functions: Beginning execution of "push"
  {"structuredData":true,"severity":"INFO","message":"Hello logs!"}
i  functions: Finished "push" in ~1s
  /Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:44
          var _this = _super.call(this, errorInfo.message) || this;
                             ^

  FirebaseMessagingError: 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>
  <HEAD>
  <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.FirebaseError [as constructor] (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:44:28)
      at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:90:28)
      at new FirebaseMessagingError (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:279:16)
      at Object.createFirebaseError (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:57:12)
      at /Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:79:51
      at process.processTicksAndRejections (node:internal/process/task_queues:95: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'
  }

  Node.js v18.0.0

I am trying to test push notifications through the firebase emulator i.e. locally. I am using cloud functions and calling the function directly.

Here are the steps:

  1. Download admin key
    enter image description here

  2. Set GOOGLE_APPLICATION_CREDENTIALS:

➜  Desktop export GOOGLE_APPLICATION_CREDENTIALS=pearl-cef7c-4833cff1a093.json
  1. Run the emulator via firebase emulators:start

  2. Try calling an FCM function: admin.messaging().sendToTopic(topic, message); via a webhook.

  3. Getting failure that Make sure the credential used to authenticate this SDK has the proper permissions.

Why would my admin key fail? I have the same issue when I use Service Accounts!

i  functions: Beginning execution of "push"
  {"structuredData":true,"severity":"INFO","message":"Hello logs!"}
i  functions: Finished "push" in ~1s
  /Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:44
          var _this = _super.call(this, errorInfo.message) || this;
                             ^

  FirebaseMessagingError: 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>
  <HEAD>
  <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.FirebaseError [as constructor] (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:44:28)
      at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:90:28)
      at new FirebaseMessagingError (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:279:16)
      at Object.createFirebaseError (/Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js:57:12)
      at /Users/me/Desktop/pearl-mobile/cloud-functions/functions/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js:79:51
      at process.processTicksAndRejections (node:internal/process/task_queues:95: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'
  }

  Node.js v18.0.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文