Created
August 6, 2015 14:10
-
-
Save jakewhiteley/606b417a5e0ee85aa386 to your computer and use it in GitHub Desktop.
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 | |
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