title: "Not sufficient permissions" google analytics API service account
body: <p>I'm trying to fetch data with the Google Analytics API through service accounts. </p>
  
  <p>I have been searching on stackoverflow how to do this and been using the exact same code found on several posts but getting problems to get it working.</p>
  
  <p>Sources:</p>
  
  <p><a href="https://stackoverflow.com/questions/9863509/service-applications-and-google-analytics-api-v3-server-to-server-oauth2-authen/10089698#10089698">Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13465689/service-applications-and-google-analytics-api-v3-error-101-neterr-connection">Service Applications and Google Analytics API V3: Error 101 (net::ERR_CONNECTION_RESET)</a></p>
  
  <p><a href="http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/prediction/serviceAccount.php" rel="nofollow noreferrer">http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/prediction/serviceAccount.php</a></p>
  
  <p>This is what i got:</p>
  
  <pre><code>require_once('googleAPIGoogle_Client.php');
  require_once('googleAPI/contrib/Google_AnalyticsService.php');
  
  const CLIENT_ID = 'xxxxxxxx001.apps.googleusercontent.com';
  const SERVICE_ACCOUNT_NAME = 'xxxxxx001@developer.gserviceaccount.com';
  
  
  $keyfile = $_SERVER['DOCUMENT_ROOT']."/xxxxxxx284-privatekey.p12";
  
  
  $client = new Google_Client();
  $client-&gt;setAccessType('offline');
  $client-&gt;setApplicationName("cc insights");
  
  
  $key = file_get_contents($keyfile);
  $client-&gt;setClientId(CLIENT_ID);
  
  $client-&gt;setAssertionCredentials(new Google_AssertionCredentials(
      SERVICE_ACCOUNT_NAME,
      array('https://www.googleapis.com/auth/analytics.readonly'),
      $key)
  );
  
  
  $service = new Google_AnalyticsService($client);
  
  $data = $service-&gt;data_ga-&gt;get("ga:xxxx7777", "2012-01-01", "2013-01-25", "ga:pageviews");
  var_dump($data);
  </code></pre>
  
  <p>when executing i got the following error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET <a href="https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3Axxxx7777&amp;start-date=2012-01-01&amp;end-date=2013-01-25&amp;metrics=ga%3Apageviews" rel="nofollow noreferrer">https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3Axxxx7777&amp;start-date=2012-01-01&amp;end-date=2013-01-25&amp;metrics=ga%3Apageviews</a>: (403) User does not have sufficient permissions for this profile.' in /Applications/XAMPP/xamppfiles/htdocs/insights/application/libraries/googleAPI/io/Google_REST.php:66 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/insights/application/libraries/googleAPI/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 /Applications/XAMPP/xamppfiles/htdocs/insights/application/libraries/googleAPI/service/Google_ServiceResource.php(178): Google_REST::execute(Object(Google_HttpRequest)) #2 /Applications/XAMPP/xamppfiles/htdocs/insights/application/libraries/googleAPI/contrib/Google_AnalyticsService.php(383): Google_ServiceResource->__call('get', Array) #3 /Applications/XAMPP/xamppfiles/htdocs/insights/application/libraries/Google.php(46): Google_DataGaServiceResource->get('g in /Applications/XAMPP/xamppfiles/htdocs/insights/application/libraries/googleAPI/io/Google_REST.php on line 66</p>
  </blockquote>
  
  <p>Because i'm using the exact same code as working examples, i think it might be a problem with the API or service account settings? </p>
  
  <p>This is the user that i added to the analytics account :
  <img src="https://i.stack.imgur.com/KJQpF.png" alt="Analytics users"></p>
  
  <p>and this is api access accounts:
  <img src="https://i.stack.imgur.com/lg3rZ.png" alt="api access"></p>
  
  <p>Does anybody know what i'm doing wrong?</p>