I try to access Google Analytics Service API from php, but Exception occurs and says
"(403) User does not have any Google Analytics account.".
But, I use exactly same Google account in both Google Analytics and API Console.
Sure, I also check Analytics API switch is ON at service console panel.
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php';
const KEY_FILE = '/path/to/my-privatekey.p12';
$client = new Google_Client();
$client->setApplicationName('MyAccessLog');
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
$key)
);
$service = new Google_AnalyticsService($client);
$profile_id = 'ga:my_profileid';
$start_date = '2013-05-01';
$end_date = '2013-05-31';
$metrics = 'ga:visits';
$optParams = array(
'dimensions'=> 'ga:date',
'sort' => '-ga:visits',
'max-results' => 10,
);
$data = $service->data_ga->get($profile_id, $start_date, $end_date, $metrics, $optParams); <= Error occurs here.