如何使用Google+ API OAuth 2.0获取朋友列表 [英] How to get the friend list using Google+ API OAuth 2.0

查看:82
本文介绍了如何使用Google+ API OAuth 2.0获取朋友列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google+登录,以检索用户的基本个人资料信息(姓名,Urls,位置,个人资料图片).但是我还想检索用户朋友的用户ID,以便我可以给他/她更好的建议,以了解用户已经在我的网站中知道谁.

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();

}

有关更多信息: https://developers.google.com/apis-explorer/#p/plus/v1/ 但是我无法弄清楚如何从他们的API中以数组的形式获取朋友列表

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

预先感谢

推荐答案

您需要使用:$plus->people->listPeople,您可以在

You need to use: $plus->people->listPeople, you can find an example of usage in the PHP quick start app.

这篇关于如何使用Google+ API OAuth 2.0获取朋友列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆