2

I made a code to display user's friends and the name,id and profile pic of the friend. The problem was to get the gender of the friend and made the code below the first code .but it does not seems to work but it works in case of getting my gender information .

 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; 

}

the code to get friends gender

$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; 

1 Answer 1

4
http://graph.facebook.com/<facebook_id>?fields=gender 

fields=gender gives you the gender for the given facebook id.

Sign up to request clarification or add additional context in comments.

4 Comments

... if the user's permissions allows to get this field publicly.
such a elegant solution for such a big code. lol . It worked like a charm thanks .
@BenMarten It does. We use it in our project, and still works. Is there a specific issue you ar efacing?
It does actually not work if you have an app_scoped_user_id :( Any ideas? workarounds?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.