【问题标题】:Access Firestore from Google Functions - Getting metadata from plugin failed with error: Could not refresh access token从 Google Functions 访问 Firestore - 从插件获取元数据失败并出现错误:无法刷新访问令牌
【发布时间】:2020-12-01 05:46:36
【问题描述】:

我正在部署一个 google 函数,该函数执行一些服务器计算并将结果写入同一项目的 Firestore 数据库中。

我按照操作指南配置功能

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

并使用以下方法访问 Firestore 数据库:

admin.firestore().collection('COLLECTION_NAME').add({data: value});

IAM 用户 ...@gcf-admin-robot.iam.gserviceaccount.com 具有分配的 Google Cloud Functions 服务代理角色。

我收到以下错误:

Error: 500 undefined: Getting metadata from plugin failed with error: Could not refresh access token: Unsuccessful response status code. Request failed with status code 500
     at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
     at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
     at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
     at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
     at Http2CallStream.outputStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
     at Http2CallStream.maybeOutputStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
     at Http2CallStream.endCall (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
     at Http2CallStream.cancelWithStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:457:14)
     at callStream.filterStack.sendMetadata.then (/workspace/node_modules/@grpc/grpc-js/build/src/channel.js:225:36)
     at process._tickCallback (internal/process/next_tick.js:68:7)
 Caused by: Error
     at WriteBatch.commit (/workspace/node_modules/@google-cloud/firestore/build/src/write-batch.js:415:23)
     at DocumentReference.create (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:283:14)
     at CollectionReference.add (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:2011:28)
     at exports.parseProduct.functions.region.https.onRequest (/workspace/index.js:55:56)
     at process._tickCallback (internal/process/next_tick.js:68:7)
   code: '500',
   details:
    'Getting metadata from plugin failed with error: Could not refresh access token: Unsuccessful response status code. Request failed with status 
   metadata: Metadata { internalRepr: Map {}, options: {} },
   note:
    'Exception occurred in retry method that was not classified as transient'

我做错了什么?

【问题讨论】:

    标签: javascript node.js google-cloud-firestore google-cloud-functions firebase-admin


    【解决方案1】:

    这似乎是一个内部问题,而不是您正在做的事情。快速搜索我在GitHubSO 中发现了一个非常相似的问题。从这些链接中,我注意到它更多的是关于图书馆,我建议联系Firebase Support,因为他们可以检查环境的内部情况,因为幕后可能会发生一些奇怪的魔法。

    【讨论】:

      【解决方案2】:

      对于任何看到上述错误消息的人。它连接(至少在这种情况下)服务帐户的权限。 我正在调整一些权限并停用了一些我认为不需要的帐户。

      其中包括“项目名称”@appspot.gserviceaccount.com 重新激活它解决了我的问题。

      如果 Google 能在这种情况下显示更有意义的错误消息,那就太好了!

      【讨论】:

        猜你喜欢
        • 2018-07-11
        • 1970-01-01
        • 2015-01-08
        • 2020-08-13
        • 2013-06-14
        • 1970-01-01
        • 1970-01-01
        • 2015-04-26
        • 2017-03-22
        相关资源
        最近更新 更多