【问题标题】:Google Cloud Function/google-auth-library: Cannot read property 'user' of undefinedGoogle Cloud Function/google-auth-library:无法读取未定义的属性“用户”
【发布时间】:2020-01-09 13:10:42
【问题描述】:

关注这个:https://medium.com/@nedavniat/how-to-perform-and-schedule-firestore-backups-with-google-cloud-platform-and-nodejs-be44bbcd64ae

代码是:

const functions = require('firebase-functions'); // is installed automatically when you init the project
const { auth } = require('google-auth-library'); // is used to authenticate your request

async function exportDB () {
    const admin = await auth.getClient({
        scopes: [                               // scopes required to make a request
            'https://www.googleapis.com/auth/datastore',
            'https://www.googleapis.com/auth/cloud-platform'
        ]
    });
    const projectId = await auth.getProjectId();
    const url = `https://firestore.googleapis.com/v1beta1/projects/${projectId}/databases/(default):exportDocuments`;
    return admin.request({
        url,
        method: 'post',
        data: {
            outputUriPrefix: 'gs://name-of-the-bucket-you-created-for-backups'
        }
    });
}

const 备份 = functions.pubsub.topic('YOUR_TOPIC_NAME_HERE').onPublish(exportDB); module.exports = { 备份};

当我去部署时:

gcloud functions deploy backup --runtime nodejs8 --trigger-topic YOUR_TOPIC_NAME_HERE

我得到错误:

错误:(gcloud.functions.deploy)操作错误:代码=3, message=加载用户代码时功能失败。错误信息:代码在 文件 index.js 无法加载。您的代码中是否存在语法错误?

详细的堆栈跟踪:TypeError:无法读取属性“用户”的 未定义

这是 google-auth-library 的东西吗?

【问题讨论】:

    标签: javascript google-cloud-functions gcloud google-auth-library


    【解决方案1】:

    我假设您正在尝试部署由 HTTP 请求触发的 GCF 功能,我建议您检查此链接 [1] 似乎是相同的用例,并且可以帮助您在 GCF 上使用带有 node.js 的 Google Cloud Datastore

    [1]How to return an entire Datastore table by name using Node.js on a Google Cloud Function

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-21
      • 1970-01-01
      • 2018-09-26
      • 2018-05-31
      • 2020-10-28
      • 2017-09-16
      • 2020-06-09
      相关资源
      最近更新 更多