@google-cloud/storage 的存储桶列表为空,但 gcloud 列表已满

buckets list is empty with @google-cloud/storage, however, gcloud list is full

提问人:Chris 提问时间:11/17/2023 更新时间:11/17/2023 访问量:34

问:

我正在尝试使用 nodejs、权限和其他一切似乎都正确无误地从 Play 管理中心获取下载报告,但我无法使用 @google-cloud 软件包列出存储桶或其文件。

我可以列出并获取所有使用gcloud storage ls

const storage = new Storage({
  keyFilename: process.env.GCP_APP_KEY,
});

async function listBuckets() {
  const [buckets] = await storage.getBuckets();

  console.log('Buckets:', buckets.length);
  buckets.forEach(bucket => {
    console.log(bucket.name);
  });
}

listBuckets().catch(console.error);
节点.js 谷歌云平台 gcloud

评论

0赞 NoCommandLine 11/18/2023
buckets.length 和 bucket.name 打印什么?
0赞 Chris 11/20/2023
它是零。我发现问题是 Play 管理中心存储桶未与任何项目关联,然后我找不到查看它的方法

答:

0赞 Plumpboy 11/17/2023 #1

尝试将 projectId 添加为与您在云仪表板中看到的项目 ID 相同的项目 ID

评论

0赞 Chris 11/17/2023
尝试过,没有任何变化,此外,project-id 位于我用于创建存储的 gcp json 文件 (keyFilename) 上
0赞 Plumpboy 11/17/2023
您需要检查配置文件是否有权执行此操作
0赞 Chris 11/17/2023
它确实有权限,我有权限错误,并通过添加到配置文件来修复:“存储管理员”