<?php

$client_id = 'xxxxxxxxxxxxxxx.apps.googleusercontent.com';
$service_account_name = 'xxxxxxxxxxxxxxx@developer.gserviceaccount.com';
$key_file_location = 'key.p12';
$bucket_name = 'mybucket';

$client = new \Google_Client();
$client->setApplicationName('Gaufrette');

$key = file_get_contents($key_file_location);
$cred = new \Google_Auth_AssertionCredentials(
    $service_account_name,
    array(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL),
    $key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($cred);
}

$service = new \Google_Service_Storage($client);
return new Gaufrette\Adapter\GoogleCloudStorage($service, $bucket_name, array(), true);
