【发布时间】:2020-01-09 13:10:42
【问题描述】:
代码是:
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