title: Error refreshing the OAuth2 token, message: '{ "error" : "unauthorized_client", "error_description" : "Unauthorized client or scope in request." }'
body: <p>When I try to fetch data from Google Analytics, I got error</p>
  
  <blockquote>
    <p>Error refreshing the OAuth2 token, message: '{ "error" :
    "unauthorized_client", "error_description" : "Unauthorized client or
    scope in request." }'</p>
  </blockquote>
  
  <p>I create project in my <a href="https://console.developers.google.com/project" rel="noreferrer">https://console.developers.google.com/project</a>, create  <strong>Service account</strong> and download .p12 key. Also enable "Analytics API" in project settings, but it doesn't work. This is my code:</p>
  
  <pre><code>    $service_account_name = '&lt;Service Email&gt;@developer.gserviceaccount.com';
      $key_file_location = '&lt;keyName&gt;.p12';
      $key = file_get_contents($key_file_location);
      $cred = new Google_Auth_AssertionCredentials(
          $service_account_name,
          array(Google_Service_Analytics::ANALYTICS),
          $key,
          'notasecret',
          'http://oauth.net/grant_type/jwt/1.0/bearer',
          '&lt;My email&gt;'
      );
  $client-&gt;getAuth()-&gt;setAssertionCredentials($cred);
  $service = new Google_Service_Analytics($client);
  $result = $service-&gt;data_ga-&gt;get("ga:&lt;profileID&gt;", "yesterday", "today", "ga:pageviews");
  print_r( $result);
  </code></pre>
  
  <p>What is wrong with my project? Please help.</p>