我已经开始使用twitter API,并希望通过在某个#hashtag下从特定用户处提取推文来过滤推文。任何想法是什么矫正语法,或者它是否可能?
这是我目前使用的代码:
<?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 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("<", "<", $feed);
$feed = str_replace(">", ">", $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);
?>
非常感谢
答案 0 :(得分:0)
您只需更改搜索参数(对于用户名为nycomed和hashtag copd)
http://search.twitter.com/search.atom?q=%23copd+OR+%23nycomed
我已经在我的主题和作品中对此进行了测试。您甚至可以直接在浏览器中进行测试。
您可以找到更多信息here