开发者

Filter tweeter feed by username and hashtag

开发者 https://www.devze.com 2023-01-21 09:52 出处:网络
I have started using the twitter API and would like to filter the tweets by just pulling in tweets from a specific user under a certain #hashtag. Any ideas what the corrent syntax would be, or if its

I have started using the twitter API and would like to filter the tweets by just pulling in tweets from a specific user under a certain #hashtag. Any ideas what the corrent syntax would be, or if its possible?

This is the code I am currently using:

 <?php  
 $username = "TwitterUsername"; // Your twitter username.  
 $limit = "5"; // Number of tweets to pull in.  

 /* These prefixes and suffixes will display before and after the entire block of      tweets. */  
 $prefix = ""; // Prefix - some text you want displayed before all your tweets.  
 $suffix = ""; // Suffix - some text you want displayed after all your tweets.  
 $tweetprefix = ""; // Tweet Prefix - some text you want displayed before each tweet.  
 $tweetsuffix = "<br>"; // Tweet Suffix - some text开发者_JAVA技巧 you want displayed after each tweet.  

 $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit;  

 function parse_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix) {  

 $feed = str_replace("&lt;", "<", $feed);  
 $feed = str_replace("&gt;", ">", $feed);  
 $clean = explode("<content type=\"html\">", $feed);  

 $amount = count($clean) - 1;  

 echo $prefix;  

 for ($i = 1; $i <= $amount; $i++) {  
 $cleaner = explode("</content>", $clean[$i]);  
 echo $tweetprefix;  
 echo $cleaner[0];  
 echo $tweetsuffix;  
 }  

 echo $suffix;  
 }  

 $twitterFeed = file_get_contents($feed);  
 parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix);  
 ?>

Many thanks


You just have to change the search parameters as this (for username nycomed and hashtag copd )

http://search.twitter.com/search.atom?q=%23copd+OR+%23nycomed

i've tested this in my theme and works.You can try it even in the browser directly.

You can find more info here

0

精彩评论

暂无评论...
验证码 换一张
取 消