是否可以从 Google Compute Engine 连接到 Google Cloud Storage?

Is there anyway to connect to Google Cloud Storage from Google Compute Engine?

目前我正在为我的 php 项目使用 google 应用程序引擎。我决定将我的项目迁移到 Google Compute Engine,但我无法通过 php 连接到 Google Cloud Storage。有没有办法解决这个问题?

更新:

我发现这是可以实现的,我需要一些使用服务器 API 获取存储内容的示例。这就是我所做的。

require_once 'GoogleAPI/autoload.php';
$projectId = "dummyid";
$client = new Google_Client();
$client->setApplicationName("Gave");
$client->setDeveloperKey("SERVERKEY");
$client->addScope(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);

$storage = new Google_Service_Storage($client);
$buckets = $storage->buckets->listBuckets($projectId);
foreach ($buckets['items'] as $bucket) {
   printf("%s\n", $bucket->getName());
}

但是还是不行。服务器密钥是否限制访问某些控件?它给我一个错误 500。

您当然可以使用 Google 计算引擎 (GCE) 中的 Google 云存储 (GCS)。您会发现它是访问 GCS 的最快方式之一。但是,当您不使用 App Engine 时,您不能使用相同的 App Engine PHP 库访问 GCS。

从 AppEngine 以外的环境使用 PHP 的规范客户端库是 Google APIs Client Library for PHP. You can find demonstrations and tutorials on accessing GCS with that library here: https://cloud.google.com/storage/docs/json_api/v1/json-api-php-samples

作为第二个选项,新的 gcloud-php 项目基本支持 GCS。

最后,作为第三个选项,public 使用 HTTP 请求直接访问 GCS 的 API 有详细的文档记录,并且在 GCE 中运行良好。