简体   繁体   中英

How to get the friend list using Google+ API OAuth 2.0

I am having signin with Google+ to retrieve the users basic profile info(Name, Urls, Location, Profile Picture). But I want to also retrieve the user-id of the users friend so that i can give him/her better suggestion of whom the user already know in my website.

$app_access_token = GetCH();
function GetCH(){
$ch = curl_init();
$pieces = explode(",", $_SESSION['access_token']); $piece = explode(":", $pieces[0]);
$token = str_replace('"',"",$piece[1]);
$url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=".$token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETU`enter code here`RNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if(substr($url,0,8)=='https://'){
    curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
}
$sendCH = curl_exec($ch);
curl_close($ch);
return $sendCH;
};

if ($client->getAccessToken()){ 
  $me = $plus->people->get('me');
  $user_id = filter_var($me['id'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
  $url = filter_var($me['url'], FILTER_VALIDATE_URL);
  $img = filter_var($me['image']['url'], FILTER_VALIDATE_URL);
  $name = filter_var($me['displayName'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);

  // The access token may have been updated lazily.
  $_SESSION['access_token'] = $client->getAccessToken();
} else {
  $authUrl = $client->createAuthUrl();

}

For More Information: https://developers.google.com/apis-explorer/#p/plus/v1/ But I am unable to figure how to get the friend list as an array from their API

Thanks in Advance

您需要使用: $plus->people->listPeople ,您可以在PHP快速 $plus->people->listPeople应用程序中找到用法示例。

First of all, you should make sure you're using the https://www.googleapis.com/auth/plus.login OAuth2 scope to make sure they permit you to access some or all of their friends lists. You want to use the people.list API access point as documented here and detailed further on this page . Although they don't give a PHP code sample, I think you'll be able to use the $plus->people->list to make the call and get the information you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM