Facebook API数据过滤

时间:2014-04-07 11:20:47

标签: facebook facebook-graph-api

我们可以在Facebook上与朋友一起拍照。

我需要以下关于朋友的数据

我们可以获得友谊日期吗?我们何时成为Facebook的朋友? 我们可以在帖子/图片或链接上一起得到我们的第一条评论吗? 我们可以获得第一个标记在一起的位置吗? 我试过这段代码

1 个答案:

答案 0 :(得分:0)

I have tried this but not get result as i required in the above.
<?php
// 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('php-fb-sdk/Facebook.php');

  $config = array(
    'appId' => '504689322987116',
    'secret' => '0a1280c39c70db2b3b502ddc6d514dea',
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();

    if($user_id) {

      // 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 name from user where uid = ' . $user_id;
        $ret_obj = $facebook->api(array(
                                   'method' => 'fql.query',
                                   'query' => $fql,
                                 ));

        // 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>Name: ' . $ret_obj[0]['name'] . '</pre>';

        //Get All my friends
        $friends = $facebook->api('me?fields=friends');
        //$friends = $facebook->api('/me/friends');
        //echo '<pre>';print_r($friends);echo '</pre>';

        echo "<h2>Select a Friend</h2>";
        echo "<span><a class='refetch' href='javascript:void(0);'><img src='images/f-cross.png' /></a></span>";
        echo "<div style='height:374px; overflow: auto' id='friends_list_id' class='friend-list'>";      
        if(count($friends[friends][data]))
        //if($friends)
        {
            //echo "<h2>My Friends (".count($friends[friends][data]).")</h2><br>";
            foreach ($friends[friends][data] as $frnd)
            //foreach ($friends['data'] as $key=>$friendList)
            {
                //echo "Name : ". $frnd[name]."<br>";
                $pic_path = "https://graph.facebook.com/".$frnd[id]."/picture";
                echo '<li><input class="my-friend-list" type="radio" name="friends" id="friends'.$frnd[id].'" value="'.$frnd[id].'"><span><img src='.$pic_path.' width="50" height="50"  /></span>';
                //echo "<label>".character_limiter($friendList['name'],30)."</label></li>";
                echo "<label>".$frnd[name]."</label></li>";
            }
        }
        else 
        {
            echo "<h2>You have No Friend</h2>";
        }
        echo "</div>";
        ?>

        <div class="content-area">

        <div id="id_f_comment"  class="sept-two">
          <p><span>First Comment?</span>
          <br /><br />
          <a rel="comments" title="First Comment?"  class="fetch_btn tooltip" href="#">Click To Get First Comment<!--<img src="images/retrieve-data.png" />--></a>
          </p>
        </div><!--id_f_comment-->
        </div>
        <?php
      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, so print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

echo "</div>";
include('include/_scripts.php'); 
?>