我制作了一个代码来显示用户的朋友以及朋友的姓名,身份证和个人资料照片。问题是获得朋友的性别并将代码设置在第一个代码下面。但它似乎不起作用,但它可以在获取我的性别信息时起作用。
function displayUsersIcons($criteria) {
$users = $criteria['users'];
$nb_display = $criteria['nb_display'];
$width = $criteria['width'];
echo 'data'.$gen = $criteria['gen'];
if($width=='') $width="200";
if($nb_display>count($users) || $nb_display=='') $nb_display=count($users); //display value never bigger than nb users
$display = '';
for($i=0;$i<$nb_display;$i++) {
$name = $users[$i]['name'];
$picture = $users[$i]['picture'];
$url = $users[$i]['url'];
$user_id = $users[$i]['id'];
$cookie = self::$cookie;
if($cookie['access_token']!='') {
$url = 'https://graph.facebook.com/'.$name.'?access_token='.$cookie['access_token'];
//echo '<a href="'.$url.'" target="_blank">'.$url.'</a><br>';
$data = json_decode($this->getDataFromUrl($url));
$fb['gender'] = $data->gender;
$gender=$fb;
$display .= '<li class="mispan main-span" gen="'.$gender.'" data="'.$user_id.'" unme="'.$name.'" upic="'.$picture.'">';
$display .= '<div class="thumbnail">';
$display .= '<h3 class="miheader">'.$name.'</h3>';
$display .= '<a href="'.$url.'" target="_blank" title="'.$name.'">';
$display .= '<div class="miprofile-pic-cnt" style="background-image:url('.$picture.')" ></div>';
$display .= '</a>';
$display .= '<div class="caption" style="text-align:center;">';
$display .= '<p><a href="#" class="btn kssico miclickks"><img src="Iconos/lips.png" /></a> <a href="#" class="btn bdico miclickbd"><img src="Iconos/bed.png" /></a></p>';
$display .= '</div>';
$display .= '</div>';
$display .= '</li>';
}
return $display;
}
获取朋友性别的代码
$cookie = self::$cookie;
if($cookie['access_token']!='') {
$url = 'https://graph.facebook.com/'.$name.'?access_token='.$cookie['access_token'];
//echo '<a href="'.$url.'" target="_blank">'.$url.'</a><br>';
$data = json_decode($this->getDataFromUrl($url));
$fb['gender'] = $data->gender;
$gender=$fb;
答案 0 :(得分:4)
http://graph.facebook.com/<facebook_id>?fields=gender
fields=gender
为您提供给定facebook ID的性别。