$client->setDeveloperKey("MY_SECRET_API");
First of all, since, as I understand it, this will not work for authentication, you will need to use OAuth2 authentication. There are two options for this: using a client identifier for a web application or using a service account. Api authorization
After that you can make such a call. (Here I use the service account)
First authenticate:
$key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/analytics.readonly'), $key ); $client->setAssertionCredentials($cred);
Call:
$ids = 'ga:123456'; //your id $startDate = '2013-12-25'; $endDate = '2014-01-08'; $metrics = 'ga:transactions'; $optParams = array( 'dimensions' => 'ga:campaign', 'max-results' => '50' ); $results = $service->data_ga->get($ids, $startDate, $endDate, $metrics, $optParams); //Dump results echo "<h3>Results Of Call:</h3>"; echo "dump of results"; var_dump($results); echo "results['totalsForAllResults']"; var_dump($results['totalsForAllResults']); echo "results['rows']"; foreach ($results['rows'] as $item) { var_dump($item); }
Prutpot
source share