Php 如何检索我在推特上发得最多的单词?
我一直在阅读twitter的开发者网站,但RESP API中没有这样做的方法,我认为这是通过流式API实现的,有人可以指导我如何做到这一点吗?我想要一些类似于tweetstats的东西,只需向我展示推文最多的单词Php 如何检索我在推特上发得最多的单词?,php,twitter,Php,Twitter,我一直在阅读twitter的开发者网站,但RESP API中没有这样做的方法,我认为这是通过流式API实现的,有人可以指导我如何做到这一点吗?我想要一些类似于tweetstats的东西,只需向我展示推文最多的单词 感谢您回答这使用了REST API,而不是流式API,但我认为它可以满足您的需求。唯一的限制是RESTAPI将其限制为最新的200条tweet,因此,如果您上周有超过200条tweet,那么它将只跟踪您最近200条tweet中的文字 请确保将API调用中的用户名替换为所需的用户名 &l
感谢您回答这使用了REST API,而不是流式API,但我认为它可以满足您的需求。唯一的限制是RESTAPI将其限制为最新的200条tweet,因此,如果您上周有超过200条tweet,那么它将只跟踪您最近200条tweet中的文字 请确保将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
}
?>
created_at)>strottime('-1周')){
$words=array_merge($words,explode(“”,$tweet->text));
}
}
//计算每个单词的值
$word\u counts=数组\u count\u值($words);
//按值降序排列数组
arsort(字数);
foreach($word_计为$word=>$count){
//你想怎么说就怎么说吧
}
?>
请帮忙,请!!一个提示,一个建议,什么基于对这个问题的回答,听起来twitter并没有保存一段我知道的历史,所以我想知道一周的时间,可以从这个开始:然后找出如何检索一周。如果你能用php explode()将你的推文存储到一个数组中,你已经成功了一半。我已经知道如何使用twitter的rest api,让我看看它感谢你的回答如果有人知道更好的方法如果你在寻找更好的,我想你需要定义“更好”