oauth - In google plus how to get the userId while the authentication code is given and google plus sign up button(php) -


<?php /*  * copyright 2011 google inc.  *  * licensed under apache license, version 2.0 (the "license");  * may not use file except in compliance license.  * may obtain copy of license @  *  *     http://www.apache.org/licenses/license-2.0  *  * unless required applicable law or agreed in writing, software  * distributed under license distributed on "as is" basis,  * without warranties or conditions of kind, either express or implied.  * see license specific language governing permissions ,  * limitations under 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 generate // oauth2_client_id, oauth2_client_secret, , register oauth2_redirect_uri.  $client->setclientid('123236981117-cr7rt023bpg3n9b698pdqhk0353hpjgi.apps.googleusercontent.com');  $client->setclientsecret('');  $client->setredirecturi('');  $client->setdeveloperkey('');   $plus = new google_plusservice($client); $oauth2 = new google_oauth2service($client);  if (isset($_request['logout'])) {   unset($_session['access_token']); }  if (isset($_get['code'])) {  // exchange oauth 2.0 authorization code user credentials.    $client->authenticate($_get['code']);      $token = json_decode($client->getaccesstoken());  // verify token    $requrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' .           $token->access_token;   $req = new google_httprequest($requrl);     $tokeninfo = json_decode(       $client::getio()->authenticatedrequest($req)->getresponsebody());    $_session['access_token'] = $client->getaccesstoken();    header('location: http://' . $_server['http_host'] . $_server['php_self']); }  if (isset($_session['access_token'])) {   $client->setaccesstoken($_session['access_token']); }  if ($client->getaccesstoken()) {   $me = $plus->people->get('me');   $user = $oauth2->userinfo->get();          // these fields filtered through 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 = "<a rel='me' href='$url'>$name</a><div><img src='$img'></div>";    $optparams = array('maxresults' => 100);   $activities = $plus->activities->listactivities('me', 'public', $optparams);     $activitymarkup = '';   foreach($activities['items'] $activity) {     // these fields filtered through 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 .= "<div class='activity'><a href='$url'>$title</a><div>$content</div></div>";   }     // access token may have been updated lazily.   $_session['access_token'] = $client->getaccesstoken(); } else {   $authurl = $client->createauthurl(); } ?> <!doctype html> <html> <head>   <meta charset="utf-8">   <link rel='stylesheet' href='style.css' /> </head> <body> <header><h1>google+ sample app</h1></header> <div class="box">  <?php if(isset($personmarkup)): ?> <div class="me"><?php print $personmarkup ?></div> <?php endif ?>  <?php if(isset($activitymarkup)): ?> <div class="activities">your activities: <?php print $activitymarkup ?></div> <?php endif ?>  <?php   if(isset($authurl)) {     print "<a class='login' href='$authurl'>connect me!</a>";   } else {    print "<a class='logout' href='?logout'>logout</a>";   } ?> </div> </body> </html> 

hey every 1 using code getting user's information , user's activites. verifing token. problem not know how google+ userid if authentication code given me.so want following thing

if there error in token info, abort.

and want add google plus sign button in appliaction.

please me out. thank

the user's userid 1 of elements returned in $me. can compare userid client side gets (and passes server) verify client isn't trying lie server is.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -