title: authentication Google Content Api service account - error 'user cannot access account'
body: <p>I am bashing my head against the wall trying to get my code to work.
  I already have succesfully connected to the google Api by using the authentication route with the redirect url.</p>
  
  <p>However, I need to get this working as a standalone service which will be running in a crontab.</p>
  
  <p>So now I am trying to authenticate with a 'service account'.</p>
  
  <p>This is my code and below that you will find the error it is giving me.</p>
  
  <pre><code>$client = new Google_Client();
  $client-&gt;setApplicationName('GoogleShoppingService');
  
  if (isset($_SESSION['service_token'])) {
      $client-&gt;setAccessToken($_SESSION['service_token']);
  }
  
  $service = new Google_Service_Content($client);
  
  $client_id = 'xxxxxxx.apps.googleusercontent.com';
  $client-&gt;setClientId($client_id);
  $service_account_name = 'xxxxxxx@developer.gserviceaccount.com';
  
  
  $key_file_location = 'privatekey.p12';
  $key = file_get_contents($key_file_location);
  $scope = 'https://www.googleapis.com/auth/content';
  $cred = new Google_Auth_AssertionCredentials(
      $service_account_name,
          array($scope),
          $key
      );
  $result = $client-&gt;setAssertionCredentials($cred);
  print_r($result);
  if($client-&gt;getAuth()-&gt;isAccessTokenExpired()) {
      $client-&gt;getAuth()-&gt;refreshTokenWithAssertion($cred);
  }
  
  $_SESSION['service_token'] = $client-&gt;getAccessToken();
  echo $client-&gt;getAccessToken();
  
  $merchantId = 1234567;//this a dummy value, I replace it with the actual merchantId
  $accountId = 1234567;//this a dummy value, I replace it with the actual accountId
  $accountstatuses = $service-&gt;accountstatuses-&gt;get($merchantId,$accountId);
  </code></pre>
  
  <p>So this is the message I get when running the code. (note that the token is created, but that I am not able to access the content of the Google Shopping feed.) </p>
  
  <pre><code>{"access_token":"ya29.NQD7MQz0cas9PhoAAADRPMlTVecqYXYh4fNoZfRMymQtSF4hwqJn31uobohLbw","expires_in":3600,"created":1404200605}
  Fatal error:
  Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/content/v2/1234567/accountstatuses/1234567: (401) User cannot access account 1234567' in /home/sites/site1/web/googleShopping2/src/Google/Http/REST.php:79
  Stack trace:
  #0 /home/sites/site1/web/googleShopping2/src/Google/Http/REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request))
  #1 /home/sites/site1/web/googleShopping2/src/Google/Client.php(499): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
  #2 /home/sites/site1/web/googleShopping2/src/Google/Service/Resource.php(195): Google_Client-&gt;execute(Object(Google_Http_Request))
  #3 /home/sites/site1/web/googleShopping2/src/Google/Service/Content.php(685): Google_Service_Resource-&gt;call('get', Array, 'Google_Service_...')
  #4 /home/sites/site1/web/googleShopping2/examples/test.php(58): Google_Service_Content_Accountstatuses_Resource-&gt;get(1234567, 1234567)
  #5 {main} thrown in /home/sites/site1/web/googleShopping2/src/Google/Http/REST.php on line 79
  </code></pre>
  
  <p>I've already tried to find a solution for 2 days now, but any hint that I've found doesn't help me. I've also creted a new project with new Api auth keys, but nothing works and I always get the above message.
  Who can help me please?</p>
  
  <p>Regards,
  Martin</p>