title: In google plus how to get the userId while the authentication code is given and google plus sign up button(php)
body: <pre><code>&lt;?php
  /*
   * Copyright 2011 Google Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  require_once '/google-api-php-client/src/Google_Client.php';
  require_once '/google-api-php-client/src/contrib/Google_PlusService.php';
  require_once '/google-api-php-client/src/contrib/Google_Oauth2Service.php';
  require_once '/google-api-php-client/src/io/Google_HttpRequest.php';
  session_start();
  
  $client = new Google_Client();
  // 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('123236981117-cr7rt023bpg3n9b698pdqhk0353hpjgi.apps.googleusercontent.com');
   $client-&gt;setClientSecret('');
   $client-&gt;setRedirectUri('');
   $client-&gt;setDeveloperKey('');
  
  
  $plus = new Google_PlusService($client);
  $oauth2 = new Google_Oauth2Service($client);
  
  if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
  }
  
  if (isset($_GET['code'])) {
  
  // Exchange the OAuth 2.0 authorization code for user credentials.
  
    $client-&gt;authenticate($_GET['code']);
       $token = json_decode($client-&gt;getAccessToken());
   // Verify the token
  
    $reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' .
            $token-&gt;access_token;
    $req = new Google_HttpRequest($reqUrl);
  
  
    $tokenInfo = json_decode(
        $client::getIo()-&gt;authenticatedRequest($req)-&gt;getResponseBody());
  
    $_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()) {
    $me = $plus-&gt;people-&gt;get('me');
    $user = $oauth2-&gt;userinfo-&gt;get();
  
          // These fields are currently filtered through the PHP sanitize filters.
    // See http://www.php.net/manual/en/filter.filters.sanitize.php
  
  
    $url = filter_var($me['url'], FILTER_VALIDATE_URL);
  
    $birth = filter_var($user['birthday'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
  
    $img = filter_var($me['image']['url'], FILTER_VALIDATE_URL);
  
    $name = filter_var($me['displayName'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
  
    $personMarkup = "&lt;a rel='me' href='$url'&gt;$name&lt;/a&gt;&lt;div&gt;&lt;img src='$img'&gt;&lt;/div&gt;";
  
    $optParams = array('maxResults' =&gt; 100);
    $activities = $plus-&gt;activities-&gt;listActivities('me', 'public', $optParams);
  
  
    $activityMarkup = '';
    foreach($activities['items'] as $activity) {
      // These fields are currently filtered through the PHP sanitize filters.
      // See http://www.php.net/manual/en/filter.filters.sanitize.php
      $url = filter_var($activity['url'], FILTER_VALIDATE_URL);
      $title = filter_var($activity['title'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
      $content = filter_var($activity['object']['content'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
  
      $activityMarkup .= "&lt;div class='activity'&gt;&lt;a href='$url'&gt;$title&lt;/a&gt;&lt;div&gt;$content&lt;/div&gt;&lt;/div&gt;";
    }
  
  
    // The access token may have been updated lazily.
    $_SESSION['access_token'] = $client-&gt;getAccessToken();
  } 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($activityMarkup)): ?&gt;
  &lt;div class="activities"&gt;Your Activities: &lt;?php print $activityMarkup ?&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>Hey every one by using this code i am getting the user's information and user's activites.
  I am also verifing the token. But the problem is i do not know how to get google+ userID if the authentication code is given to me.so i want to do the following thing</p>
  
  <p>If there was an error in the token info, abort.</p>
  
  <p>And i want to add the google plus sign up button also in to my appliaction.</p>
  
  <p>Please Somebody help me out. Thank you </p>