Google Analytics Service API returns "(403) User does not have any Google Analytics account."

1,832 views
Skip to first unread message

Ko-hei OHTSUKA

unread,
Jun 24, 2013, 3:32:02 AM6/24/13
to google-api...@googlegroups.com
Hello,

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.

What should I check next?

My code is,

<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php';

const SERVICE_ACCOUNT_NAME = 'my_email_...@developer.gserviceaccount.com';

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.

Ko-hei OHTSUKA

unread,
Jun 24, 2013, 4:03:08 AM6/24/13
to google-api...@googlegroups.com
I solved this problem by finding this site:

Hello,

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.

What should I check next?

My code is,

<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php';

Reply all
Reply to author
Forward
0 new messages