【问题标题】:Getting previous statuses from $facebook->api('/me/feed')从 $facebook->api('/me/feed') 获取以前的状态
【发布时间】:2011-09-02 15:45:22
【问题描述】:

我一直在尝试访问当前用户(登录的用户)之前发布的状态。它似乎不可靠,返回的状态数量似乎有所不同。

我知道您可以使用 ?limit=、?since= 和 ?until=,但是当我使用 ?limit=1000 时,这表示足够大,可以让用户之前发布的一些帖子变得不可预测。

我想做的是访问我加入 Facebook 后发布的前几个状态。最好的方法是什么?(使用 '?limit=1000' 似乎有点过分了!)

这会设置权限等,然后抓取提要:

require 'php-sdk/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxx', 
  'cookie' => true
));

$user = $facebook->getUser();

// Permissions required
$par = array();
$par['scope'] = "status_update user_about_me user_status";

$feed = null;
$profile = null;
$loginUrl = null;

if ($user) {
    $logoutUrl = $facebook->getLogoutUrl();
    try {
        // Proceed knowing you have a user who is logged in and authenticated

        // Get Feed
        $feed = $facebook->api('/me/feed');
        // Get User Profile
        $profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }   
} 
else {
    $loginUrl = $facebook->getLoginUrl($par);
}

?>

这是我用来显示来自提要的状态更新的内容:

foreach ($feed['data'] as $entry)
{
    // If its a message posted by user
    $isStatusUpdate = array_key_exists('message', $entry) and $entry['from']['name'] == $profile['name'];

    if ($isStatusUpdate)
    {
        $likes = 0;
        $comment = 0;

        // Get num of likes 
        if (array_key_exists('likes', $entry))
            $likes = count($entry['likes']); 

        // Get num of comments
        if (array_key_exists('comments', $entry))
            $comments = count($entry['comments']);

        // Display message with num of likes and comments
        echo '<div class="row"><div class="span4 columns"><h2>Post '.$counter.'</h2>';
        echo '<p>Likes '.$likes.'</br>';
        echo 'Comments '.$comments.'</p></div>';
        echo '<div class="span12 columns"><h3>'.substr($entry['created_time'], 0, 10).'</h3>';
        echo '<pre class="prettyprint">'.$entry['message'].'</pre></div>';
    }
}

【问题讨论】:

    标签: php facebook facebook-graph-api facebook-php-sdk


    【解决方案1】:

    你不能做limit=1000,我对你得到意想不到的结果并不感到惊讶。您一次可以请求的数量是有上限的,即使没有,您也很可能会超时并且只接收部分数据。

    但是,您可以做的是发送一个使用“since”字段的请求,该字段已成为过去,因此肯定是在用户成为 facebook 会员之前。例如,如果您使用 2000 年 1 月 1 日的起始日期,您将获得用户转发的第一个帖子的列表。

    希望有帮助

    【讨论】:

    • 感谢您的帮助!,我已经尝试过了,它确实有效,无论如何 - 我正在考虑使用 FQL,因为这似乎更适合我尝试做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多