我希望通过获取用户朋友列表并在我的应用程序中显示其详细信息来进一步使用API。
在旧版本中,我使用
$facebook->api_client->friends_get
和
$facebook->api_client->users_getInfo
但在facebook 2012中,我不知道如何使用?
有些人帮助我。
答案 0 :(得分:0)
示例:
<?
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('src/facebook.php');
$config = array(
'appId' => '*******',
'secret' => '************',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?
if(empty($user_id)){
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $GLOBALS['config']['appid'] . "&redirect_uri=" . urlencode($my_url)."&scope=friends_hometown";
echo ("<script> top.location.href='".$dialog_url ."' </script>");
}
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$fql = 'SELECT pic_square,hometown_location,name,sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())';
$ret_obj = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql,
));
$count=count($ret_obj);
echo '<pre>';
for($i=0;$i<$count;$i++){
echo 'Name: ' . $ret_obj[$i]['name'];
echo '<br />';
echo 'Sex:' . $ret_obj[$i]['sex'];
echo '<br />';
echo 'Home :' . $ret_obj[$i]['hometown_location']['city'];
echo '<br />';
}
// FQL queries return the results in an array, so we have
// to get the user's name from the first element in the array.
echo'</pre>';
} catch(FacebookApiException $e) {
error_log($e->getType());
error_log($e->getMessage());
}
?>
</body>
</html>
你可以使用php Sdk &安培;获得用户之友 使用此代码
$friends=$facebook->api('me/friends/,'GET');
&安培;关于信息,它取决于你想要什么信息,如果你只是想要名字和&amp;其他非常公开的信息上面的代码就足够了