我正试图在我的PHP项目中使用,但在AppEngine平台上没有使用。我发现的所有链接和教程都使用AppEngine平台,因此可以使用gs://链接。有没有人知道如何连接,例如,列出桶中的对象--或者至少连接到没有AppEngine的存储槽php?
发布于 2014-09-03 19:50:23
试试下面的代码:
set_include_path("../src/" . PATH_SEPARATOR . get_include_path());
require_once 'Google/Client.php';
require_once("Google/Service/Storage.php");
$client_id = '<client-id>'; //Client ID
$service_account_name = '<service_account_name(email)>'; //Email Address
$key_file_location = 'key.p12'; //your key.p12 file
echo pageHeader("Service Account Access");
if ($client_id == '<YOUR_CLIENT_ID>'
|| !strlen($service_account_name)
|| !strlen($key_file_location)) {
echo missingServiceAccountDetailsWarning();
}
$client = new Google_Client();
$client->setApplicationName("<your application name>");
$service = new Google_Service_Storage($client);
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/devstorage.full_control'),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
$acl = new Google_Service_Storage_ObjectAccessControl();
$acl->setEntity('allUsers');
$acl->setRole('READER');
$acl->setBucket('<your bucket name>');
$acl->setObject('your object name');
$service = new Google_Service_Storage($client);
$return_value = $service->objects->get('<bucket_name>','<object-name>');发布于 2014-05-24 22:40:43
您可以使用JSON api。
要想看到它付诸行动,就在这里:
https://developers.google.com/apis-explorer/#p/storage/v1/storage.objects.list
然后在右上角启用OAuth2,并填写桶名以查看示例请求和响应。
https://stackoverflow.com/questions/23843638
复制相似问题