title: Get Userinfo from Google OAuth 2.0 PHP API
body: <p>I am trying to use Google Oauth API to get userinfo.
  It works perfectly for Google Plus API but I am trying to create a backup in case the user doesn't have google plus account.
  The authentication process is correct and I even get the $userinfo object but how exactly do I access the properties. I tried $userinfo->get() but it only return the id of the user.</p>
  
  <p>Am I doing something wrong? Here is the code that I am using...<br>
      
  
  <pre><code>require_once '../../src/Google_Client.php';
  require_once '../../src/contrib/Google_Oauth2Service.php';
  
  session_start();
  
  $client = new Google_Client();
  $client-&gt;setApplicationName("Google+ PHP Starter Application");
  // Visit https://code.google.com/apis/console to generate your
  // oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
   $client-&gt;setClientId('*********************');
   $client-&gt;setClientSecret('**************');
   $client-&gt;setRedirectUri('***************');
   $client-&gt;setDeveloperKey('**************');
  $plus = new Google_Oauth2Service($client);
  
  if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
  }
  
  if (isset($_GET['code'])) {
    $client-&gt;authenticate($_GET['code']);
    $_SESSION['access_token'] = $client-&gt;getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
  }
  
  if (isset($_SESSION['access_token'])) {
    $client-&gt;setAccessToken($_SESSION['access_token']);
  }
  
  if ($client-&gt;getAccessToken()) 
  {
      $userinfo = $plus-&gt;userinfo;
      print_r($userinfo-&gt;get());
  
  } else 
  {
      $authUrl = $client-&gt;createAuthUrl();
  }
  ?&gt;
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;link rel='stylesheet' href='style.css' /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;header&gt;&lt;h1&gt;Google+ Sample App&lt;/h1&gt;&lt;/header&gt;
  &lt;div class="box"&gt;
  
  &lt;?php if(isset($personMarkup)): ?&gt;
  &lt;div class="me"&gt;&lt;?php print $personMarkup ?&gt;&lt;/div&gt;
  &lt;?php endif ?&gt;
  
  &lt;?php
    if(isset($authUrl)) {
      print "&lt;a class='login' href='$authUrl'&gt;Connect Me!&lt;/a&gt;";
    } else {
     print "&lt;a class='logout' href='?logout'&gt;Logout&lt;/a&gt;";
    }
  ?&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks...</p>
  
  <p><em><strong></em>**EDIT*<em>*</em>*</strong>
  Was missing Scopes--Added</p>
  
  <pre><code> $client-&gt;setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));
  </code></pre>
  
  <p>works now...</p>