如何检索我在推特上发得最多的单词


how do I retrieve the words that I tweeted most?

我一直在阅读推特的开发者网站,但在RESP API中没有这样做的方法,我认为是通过流API,有人能指导我如何做到这一点吗?,我想要一些类似推特的东西,只要给我看推特上最多的单词。

感谢您回答

这使用REST API,而不是Streaming API,但我认为它可以满足您的需求。它的唯一限制是,它被REST API限制为最新的200条推文,所以如果你在上周有200条以上的推文,那么它将只跟踪你最近200条推特中的单词。

请确保将API调用中的用户名替换为所需的用户名。

<?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
}
?>