代码之家  ›  专栏  ›  技术社区  ›  Zorayr

FCM凭据在firebase模拟器中失败

  •  0
  • Zorayr  · 技术社区  · 4 年前

    我正在尝试通过firebase模拟器(即本地)测试推送通知。我正在使用云函数并直接调用该函数。

    以下是步骤:

    1. 下载管理密钥 enter image description here

    2. 设置 GOOGLE_APPLICATION_CREDENTIALS :

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

    2. 尝试调用FCM函数: admin.messaging().sendToTopic(topic, message); 通过网络挂钩。

    3. 正在获取失败 Make sure the credential used to authenticate this SDK has the proper permissions.

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

    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
    
    0 回复  |  直到 4 年前
    推荐文章