Is there a way to get all tweets from twitter for a specified user?
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);
ech开发者_Go百科o $page;
}
getTweets('user_name');
Is there a way to get round that?
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.
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.
They only return a maximum of 3200 tweets per user by calling GET statuses/user_timeline, for more info look here: https://dev.twitter.com/discussions/1157
精彩评论