views:

50

answers:

2

I wanted to write a function for grabbing all tweets for specified user, but it returns only 20 most recent.

I came up with something like that:

function getTweets($user) {

    $page = file_get_contents("http://twitter.com/{$user}");
    $from = strpos($page, "<ol id='timeline' class='statuses'>");
    $to = strpos($page, "</ol>");
    $length = $to - $from;
    $page =substr($page, $from, $length);
    echo $page;
}

getTweets('user_name');

Is there a way to get round that?

A: 

Twitter Libraries has libs for php listed. If you can grab a single users all tweets or not I'm afraid I don't know but the libs should be a good starting point.

Don
+2  A: 

Twitter has an API that you should be querying to retrieve data such as tweets. It is far more efficient than crawling the HTML.

The statuses/user_timeline API service returns a list of tweets from any non-protected user. Here's an example of this service, configured to retrieve tweets for the user FRKT_ (that's me). You can customize the data it returns in many ways, such as by appending the count variable to the URL like so to specify how many tweets you'd like to retrieve.

You should use an XML parser such as SimpleXML rather than miscellaneous string functions such as strpos like you demonstrated to parse the data returned from the API.

Johannes Gorset
Damn. I missed the `count` parameter. I think, that should do the trick. Now I will definitely use the Twitter API.
Eugene