将 google-cloud 与 firebase 功能集成

Integrate google-cloud with firebase functions

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

应该包含一个 json 文件,其中包含秘密凭据和密钥:

var config = {

projectId: 'grape-spaceship-123',

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

};

使用firebase函数/google云函数时,如何实现?

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

const gcs = require('@google-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'