Skip to content

Instantly share code, notes, and snippets.

@jakewhiteley
Created August 6, 2015 14:10
Show Gist options
  • Save jakewhiteley/606b417a5e0ee85aa386 to your computer and use it in GitHub Desktop.
Save jakewhiteley/606b417a5e0ee85aa386 to your computer and use it in GitHub Desktop.
<?php
function __construct ()
{
parent::__construct();
// accessed via google developer console
$client_email = '****@developer.gserviceaccount.com';
$private_key = file_get_contents(__DIR__ .'/secure.p12');
$scopes = array(\Google_Service_Analytics::ANALYTICS_READONLY);
$user_to_impersonate = '****';
$credentials = new \Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
$user_to_impersonate
);
$client = new \Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired())
$client->getAuth()->refreshTokenWithAssertion();
// set reference for instance methods
$this->client = &$client;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment