GoogleCloudStorage.php.dist 756 B

1234567891011121314151617181920212223
  1. <?php
  2. $client_id = 'xxxxxxxxxxxxxxx.apps.googleusercontent.com';
  3. $service_account_name = 'xxxxxxxxxxxxxxx@developer.gserviceaccount.com';
  4. $key_file_location = 'key.p12';
  5. $bucket_name = 'mybucket';
  6. $client = new \Google_Client();
  7. $client->setApplicationName('Gaufrette');
  8. $key = file_get_contents($key_file_location);
  9. $cred = new \Google_Auth_AssertionCredentials(
  10. $service_account_name,
  11. array(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL),
  12. $key
  13. );
  14. $client->setAssertionCredentials($cred);
  15. if ($client->getAuth()->isAccessTokenExpired()) {
  16. $client->getAuth()->refreshTokenWithAssertion($cred);
  17. }
  18. $service = new \Google_Service_Storage($client);
  19. return new Gaufrette\Adapter\GoogleCloudStorage($service, $bucket_name, array(), true);