Skip to content

Instantly share code, notes, and snippets.

@DazWilkin
Created September 23, 2017 18:06
Show Gist options
  • Save DazWilkin/d65e9f11f0c7cf1dc1196d0db20d57da to your computer and use it in GitHub Desktop.
Save DazWilkin/d65e9f11f0c7cf1dc1196d0db20d57da to your computer and use it in GitHub Desktop.
Medium:170923: Cloud Storage w/ API Client Library for PHP
<?php
require_once 'vendor/autoload.php';
define("PROJECT_ID", [[YOUR-PROJECT-ID]]);
define("BUCKET_NAME", [[YOUR-BUCKET-NAME]]);
$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());
$request = $service->objects->listObjects(BUCKET_NAME);
foreach ($request["items"] as $object)
printf("%s\n", $object->getName());
?>
{
"require": {
"google/apiclient": "^2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment