Created
April 2, 2014 14:12
-
-
Save mppatterson/9934981 to your computer and use it in GitHub Desktop.
Connecting to Google Analytics via a service object (server-to-server)
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
// Setup the service object | |
$client_id = 'xxx.apps.googleusercontent.com'; | |
$service_account_name = 'xxx@developer.gserviceaccount.com'; | |
$client_secret = 'notasecret'; | |
$keyfile = 'path_to_your_key.p12'; | |
$client->setClientSecret($client_secret); | |
$client->setAssertionCredentials( | |
new Google_Auth_AssertionCredentials( | |
$service_account_name, | |
array('https://www.googleapis.com/auth/analytics'), | |
file_get_contents($keyfile) | |
) | |
); | |
$client->setClientId($client_id); | |
$client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly')); | |
$analytics = new apiAnalyticsService($client); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment