【发布时间】:2023-03-11 23:40:01
【问题描述】:
我正在运行节点以从谷歌云存储下载销售报告。 我得到了 credentials.json 文件。现在的问题是每次我运行我的应用程序时,我都会得到“xxxxxxx@gmail.com”没有 storage.objects.get access to the Google Cloud Storage object”。
是的,这封电子邮件没有在谷歌云存储上注册或被授予权限,但它应该单独使用凭据,不是吗? 凭据直接来自谷歌云存储,并包含以下信息: client_secret,project_id,redirect_uri,client_id...
我的示例代码:
// Imports the Google Cloud client library.
const {Storage} = require('@google-cloud/storage');
const projectId = 'xxxxxxxxxxxxxxxxxx'
const key = 'credentials.json'
const bucketName = 'pubsite.......'
const destFileName = './test'
const fileName = 'salesreport_2020.zip'
// Creates a client
const storage = new Storage({projectId, key});
async function downloadFile() {
const options = {
destination: destFileName,
};
// Downloads the file
await storage.bucket(bucketName).file(fileName).download(options);
console.log(
`gs://${bucketName}/${fileName} downloaded to ${destFileName}.`
);
}
downloadFile().catch(console.error);
【问题讨论】:
标签: api oauth-2.0 oauth google-api google-cloud-storage