【问题标题】:Integrate google-cloud with firebase functions将 google-cloud 与 firebase 功能集成
【发布时间】:2017-08-20 13:30:44
【问题描述】:

在 node.js 上集成谷歌云时,如下所述: https://www.npmjs.com/package/google-cloud

应该包含一个带有秘密凭据和密钥的 json 文件:

var config = {

projectId: 'grape-spaceship-123',

keyFilename: '/path/to/keyfile.json'

};

在使用firebase函数/google cloud函数时,怎么做?

【问题讨论】:

    标签: firebase google-cloud-platform google-cloud-functions google-cloud-storage


    【解决方案1】:

    Cloud Functions 已作为受信任的云帐户运行。在大多数情况下,您不需要添加凭证 JSON 文件。例如,这是how we initialize Cloud Storage in one of our apps

    const gcs = require('@google-cloud/storage')();
    

    如您所见,我们没有传递任何授权信息,但代码仍然能够访问 Cloud Storage:

    const file = gcs.bucket('YOUR_FIREBASE_PROJECT_ID.appspot.com').file(filePath);
    

    如果您有需要凭证文件的情况:

    1. Download the JSON file with the credentials
    2. 将 JSON 文件放入 `functions 目录。
    3. 从您的代码中引用它:keyFilename: './keyfile.json'

    【讨论】:

      猜你喜欢
      • 2018-06-02
      • 2020-12-23
      • 2021-01-13
      • 2023-04-03
      • 2018-03-04
      • 1970-01-01
      • 2018-06-25
      • 2018-12-27
      相关资源
      最近更新 更多