Twitter Favorites and more than 20
Im using curl to fetch my Twitter favorites:
<?php
$username = "bob";
$password = "password";
$twitterHost = "http://twitter.com/favorites.xml";
$curl;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_URL, $twitterHost);
$result = curl_exec($curl);
curl_close($curl);
header('Content开发者_开发知识库-Type: application/xml; charset=ISO-8859-1');
print $result;
?>
However this only fetches the last 20 favorites, not all of them.
If i amend this line:
$twitterHost = "http://twitter.com/favorites.xml";
And change it to:
$twitterHost = "http://twitter.com/favorites.xml?page=2";
I can get the next set of 20 favorites.
There doesnt appear to be anyway, using the Twitter API, to find out how many pages of favorites there are.
As such can anyone suggest the best way to get all favorites?
Or if this is not possible, get all the Tweets for a date range?
You should be able to call this API function:
http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users%C2%A0show
This API call "users/show" returns an attribute "favourites_count" which has this information. For example, go to this page to see, replacing "bob" with your username:
http://api.twitter.com/1/users/show/bob.xml
精彩评论