php - PHP 的 Google Cloud Storage 问题
问题描述
我正在使用这个库:google/cloud-storage
.
在我的储藏室里,我做了一个桶,叫做:mycustombucket
. 我的目标是在该存储桶中上传一个 csv 文件。这是我的代码:
$storage = new StorageClient([
'projectId' => 'my project id',
'keyFile' => json_decode('{
"web":{
"client_id":"my client id",
"project_id":"my project id",
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"my auth value",
"client_secret":"my client secret"
}
}', true)
]);
$bucket = $storage->bucket('mycustombucket');
$bucket->upload(
fopen('path/to/my/file.csv', 'r')
);
不幸的是,我收到了这个错误信息:json key is missing the type field
。我发现了这个类似的POST,但它对我不起作用。我认为它也已经过时了。
你能建议我和想法,如何解决这个问题?
谢谢!
解决方案
请注意,一旦生成,您将自动下载它。下载按钮将不再可用。因此,请确保您在生成密钥后拥有密钥。我希望有一个下载按钮service account
,就像我有的一样OAuth 2.0 Client IDs
(见我的帖子)。但我没有:(。最后我的代码:
$storage = new StorageClient([
'projectId' => 'projectId' => 'my project id',
'keyFile' => json_decode('{
"type": "service_account",
"project_id": "my project id",
"private_key_id": "my key id",
"private_key": "my key",
"client_email": "email@email.com",
"client_id": "client id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "url here"
}', true)
]);
推荐阅读
- testing - PM2 Testcafe fs 操作导致崩溃
- scala - 关于在 scala 中使用 spark 数据框的说明
- wordpress - 如何在我的网站上显示这样的 Woocommerce 定价变量?
- java - 我想通过递归算法在链表中找到最大节点,但我的代码有问题
- python - 按二维索引对三维 numpy 数组进行排序
- uwp - UWP 性能:Task.Run() 与后台服务
- javascript - Javascript:是否只有一页的 sessionStorage 或 localStorage 之类的东西?
- c# - 如何使用 foreach 终止和重新启动
- node.js - 为什么微软用 NodeJS 而不是 .NET 制作 Visual Studio Code?
- javascript - IE 11 不加载 JS 脚本(将其从开发者工具的脚本列表中删除)