title: 401 invalid credentials with oauth 2.0 google + api ,throwing apiServiceException..why so..?
body: <p>This is how I code to get authenticate user with google and displaying basic things.</p>
  
  <p>Getting error while authenticate user with google</p>
  
  <blockquote>
    <p>Error : invalid credentials with oauth 2.0 google + api ,throwing apiServiceException</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  require_once 'google-api-php-client/src/apiClient.php';
  require_once 'google-api-php-client/src/contrib/apiPlusService.php';
  require_once 'google-api-php-client/src/contrib/apiOauth2Service.php';
  
  session_start();
  
  $client = new apiClient();
  
  $client-&gt;setApplicationName('demo');
  $client-&gt;setClientId('asd6354egfdgtdewd');
  $client-&gt;setClientSecret('-ooRVhB5nbdsfisfgf7s6fsfsfj');
  $client-&gt;setRedirectUri('http://demo.com');
  $client-&gt;setDeveloperKey('HGFHJVhjb894rbbvjhdfjdsvkbdvdv');
  
  $client-&gt;setScopes(array('https://www.googleapis.com/auth/plus.me',
                               'https://www.googleapis.com/auth/userinfo.email'));
  
  $plus   = new apiPlusService($client);
  $oauth2 = new apiOauth2Service($client);
  
  if (isset($_REQUEST['logout']))
  {
      unset($_SESSION['access_token']);
  }
  
  if (isset($_GET['code']))
  {
      $client-&gt;authenticate();
      $_SESSION['access_token'] = $client-&gt;getAccessToken();
      header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
              # FIXME Is exit() missing?
  }
  
  if (isset($_SESSION['access_token']))
  {
      $client-&gt;setAccessToken($_SESSION['access_token']);
  }
  
  if ($client-&gt;getAccessToken())
  {
          $me   = $plus-&gt;people-&gt;get('me');
          $user = $oauth2-&gt;userinfo-&gt;get();
  
              $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
  
              $optParams = array('maxResults' =&gt; 100);
          $activities = $plus-&gt;activities-&gt;listActivities('me', 'public',$optParams);
  
          $_SESSION['access_token'] = $client-&gt;getAccessToken();
  
      } else {
  
             $authUrl = $client-&gt;createAuthUrl();
  
  }
  </code></pre>