Created
September 23, 2017 18:06
-
-
Save DazWilkin/d65e9f11f0c7cf1dc1196d0db20d57da to your computer and use it in GitHub Desktop.
Medium:170923: Cloud Storage w/ API Client Library for PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"google/apiclient": "^2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment