I have been reading the developers site of twitter, but there is not a method in the RESP API for doing that, I think It is with the Streaming Api, can someone guide me how to do this?, I want something similar to tweetstats, just show me the most tweeted words.
thanks for answering
Tweets more than a week old may fail to display in timelines or search because of indexing capacity restrictions. Old Tweets are never lost, but cannot always be displayed.
This uses the REST API, not the Streaming API, but I think it will do what you are looking for. The only limitation on it is that it is limited by the REST API to the latest 200 tweets, so if you have more than 200 tweets in the last week then it will only track words from your most recent 200 tweets.
Be sure to replace the username in the API call with your desired username.
<?php
//Get latest tweets from twitter in XML format. 200 is the maximum amount of tweets allowed by this function.
$tweets = simplexml_load_file('https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=kimkardashian&count=2');
//Initiate our $words array
$words = array();
//For each tweet, check if it was created within the last week, if so separate the text into an array of words and merge that array with the $words array
foreach ($tweets as $tweet) {
if(strtotime($tweet->created_at) > strtotime('-1 week')) {
$words = array_merge($words, explode(' ', $tweet->text));
}
}
//Count values for each word
$word_counts = array_count_values($words);
//Sort array by values descending
arsort($word_counts);
foreach ($word_counts as $word => $count) {
//Do whatever you'd like with the words and counts here
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With