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?

<section>
<?php
      $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">
          <?php
            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.
          ?>
          <li>
          <a href="https://www.facebook.com/<?php echo he($id); ?>" target="_top">
              <img src="https://graph.facebook.com/<?php echo he($id) ?>/picture?type=square" alt="<?php echo he($item); ?>">
             <?php echo he($item); ?>
            </a>
            <?php echo he($gender); ?>
          </li>
          <?php
            }
          ?>
        </ul>
      </div>


</section>

Recommended Answers

All 3 Replies

<?php
session_start();


# We require the library
require("facebook.php");

# Creating the facebook object
$facebook = new Facebook(array(
    'appId'  => 'XXXXXXXXXXXXXXX',
    'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    '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.