Google Cloud Function/google-auth-library:无法读取未定义的属性"user"



遵循这个: 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 backup = functions.pubsub.topic('YOUR_TOPIC_NAME_HERE'(.onPublish(exportDB(; 模块导出 = { 备份 };

当我通过以下方式进行部署时:

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

我收到错误:

错误: (gcloud.functions.deploy( 操作错误: 代码 = 3, 消息=函数在加载用户代码时失败。错误消息:代码 无法加载文件索引.js。您的代码中是否存在语法错误?

详细的堆栈跟踪: 类型错误: 无法读取属性"用户" 定义

这是谷歌身份验证库的东西吗?

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

[1] 如何在 Google Cloud Function 上使用 Node.js 按名称返回整个数据存储表

相关内容

最新更新