PHP code example of phpexperts / gcloud-auth
1. Go to this page and download the library: Download phpexperts/gcloud-auth library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpexperts / gcloud-auth example snippets
use PHPExperts\GoogleCloudAuth\GoogleCloudAuth;
use PHPExperts\RESTSpeaker\RESTSpeaker;
$api = new RESTSpeaker(new GoogleCloudAuth('relative/path/to/services.json'));
use PHPExperts\GoogleCloudAuth\GoogleCloudAuth;
$gcloudAuth = new GoogleCloudAuth('relative/path/to/services.json');
// Returns the raw Oauth2Token as a string.
$gcloudOauth2Token = $gcloudAuth->obtainGCloudOauthToken();
$url = "https://storage.googleapis.com/storage/v1/b?project=$projectId";
$http = new \GuzzleHttp\Client([
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => "Bearer $gcloudOauth2Token",
]
]);
$response = $http->get($url);