Getting previous statuses from $facebook->api('/me/feed')
I've been trying to access previous statuses posted by current user (the one that logs in). It seems to be unreliable and the number of statuses returned seems to vary.
I understand that you can use ?limit=, ?since= and ?until=, however when I use ?limit=1000 thats say large enough to get some of the earlier posts made by the user it becomes unpredictable.
What I want to be able to do is access the first few statuses I've posted since I joined Facebook. What would the best way to do this? (Using '?limit=1000' seems a bit excessive!)
This sets permissions etc and then grabs the feed:
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);
}
?>
This is what I'm using to display the statuses updates from the feed:
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>';
}
}
You can not do limit=1000, and I'm not surprised you are getting unexpected results. There is an upper limit to how many you can request at one time, even if there was not you would more then likely get a timeout and only receive partial data.
What you could do however is send a request that uses a 'since' field that is forever ago in the past so that is certainly before the user became a facebook member. For instance if you were to use a since date of 1/1/2000 you would get a list of posts from the first one the user made forward.
Hope that helps
精彩评论