我真的很难尝试连接Google Storage。我所需要的就是能够将PDF文件上传到我在Google Storage Console上创建的存储桶。文档似乎到处都是,缺少简单的PHP代码示例。下面是我到目前为止所做的工作:
已安装云存储
$ composer require google/cloud-storage
根据Google的要求添加计费。已启用云存储API。创建工程并添加bucket。
尝试使用以下示例:
require '../vendor/autoload.php';
define("PROJECT_ID", "my-project");
define("BUCKET_NAME", "my-bucket");
$client = new Google_Client();
$client->setApplicationName("API_Cloud_Storage");
$client->useApplicationDefaultCredentials();
$client->setScopes(["https://www.googleapis.com/auth/cloud-platform"]);
$service = new Google_Service_Storage($client);
$request = $service->buckets->listBuckets(PROJECT_ID);
foreach ($request["items"] as $bucket)
printf("%s\n", $bucket->getName());
不断得到错误
Fatal error: Uncaught Error: Class 'Google_Client' not found in /home/domain/public_html/test.php:11 ...
我知道供应商/autoload.php文件正在加载,因为我在其他脚本中使用AWS没有任何问题。我甚至连第一行都没通过。我遗漏了什么?
发布于 2019-05-16 19:21:42
您有一个带有PHP示例和详细说明的the documentation page for Cloud Storage Client Libraries。除了ceejayoz在评论中分享的链接外,还有一个指向the GitHub repo的快速入门链接。
https://stackoverflow.com/questions/56154539
复制相似问题