Twitter Favorites and more than 20

Posted by danit on Stack Overflow See other posts from Stack Overflow or by danit
Published on 2010-03-21T10:30:28Z Indexed on 2010/03/21 10:31 UTC
Read the original article Hit count: 227

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about twitter