This is the code I made for my facebook application but it is not giving the result. This code generate friends name, id and gender and I simply want to display in my apps. Please help me in solving the problem?

      $friends = idx($facebook->api('/me?fields=friends.limit(10).fields(gender,name)'),'data', array('access token' =>$accessToken));
<div class="list">
        <h3>Your friends</h3>
        <ul class="things">
            foreach ($friends as $friend) {
              // Extract the pieces of info we need from the requests above
                 $id = idx($friend, 'id');
            $item = idx($friend, 'name'); 
            $gender= idx($friend,'gender');

              // This display's the object that the user liked as a link to
              // that object's page.
          <a href="<?php echo he($id); ?>" target="_top">
              <img src="<?php echo he($id) ?>/picture?type=square" alt="<?php echo he($item); ?>">
             <?php echo he($item); ?>
            <?php echo he($gender); ?>


Recommended Answers

All 3 Replies


# We require the library

# Creating the facebook object
$facebook = new Facebook(array(
    'appId'  => 'XXXXXXXXXXXXXXX',
    'cookie' => true

$session = $facebook->getSession();
if ($session) {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
    $friends = $facebook->api('/me/friends');

foreach ($friends as $key=>$value) {
    echo '<ul id="friendsList">';
    foreach ($value as $fkey=>$fvalue) {
    if($fvalue->gender == "female") {
    echo '<li>$fvalue->name </li>';
    echo '</ul>';

I tried it but never worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.