title: Google Analytics API Returning 401 On Example Code
body: <p>I am attempting to retrieve the data from our content experiments from google analytics...</p>
  
  <p>I am using the following code, my creds are good, and have been censored for this post...</p>
  
  <pre><code>&lt;?php
  require_once 'Google/Client.php';
  require_once 'Google/Service/Analytics.php';
  
  session_start();
  
  $client = new Google_Client();
  $client-&gt;setApplicationName('Hello Analytics API Sample');
  
  // Visit https://cloud.google.com/console to generate your
  // client id, client secret, and to register your redirect uri.
  $client-&gt;setDeveloperKey('xxxxx');
  
  $service = new Google_Service_Analytics($client);
  try {
  $results = $service-&gt;management_experiments-&gt;listManagementExperiments('xxxx', 'xxxx', 'xxxx');
  } catch (apiServiceException $e) {
    print 'There was an Analytics API service error ' . $e-&gt;getCode() . ':' . $e-&gt;getMessage();
  
  } catch (apiException $e) {
    print 'There was a general API error ' . $e-&gt;getCode() . ':' . $e-&gt;getMessage();
  }
  echo '&lt;pre&gt;';
  print_r($results);
  echo '&lt;/pre&gt;';
  </code></pre>
  
  <p>I am using the following example ....</p>
  
  <p><a href="https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtExperimentsGuide#list" rel="nofollow">https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtExperimentsGuide#list</a></p>
  
  <p>Any ideas on why I am getting a 401 unauthorized? That a login is required?</p>