11
08月
2015
38. 获取一个特定话题标签的所有 Tweets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
function getTweets( $hash_tag ) {
$url = 'http://search.twitter.com/search.atom?q=' .urlencode( $hash_tag ) ;
echo "<p>Connecting to <strong>$url</strong> ...</p>" ;
$ch = curl_init( $url );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ( $ch );
curl_close ( $ch );
//If you want to see the response from Twitter, uncomment this next part out:
//echo "<p>Response:</p>";
//echo "<pre>".htmlspecialchars($xml)."</pre>";
$affected = 0;
$twelement = new SimpleXMLElement( $xml );
foreach ( $twelement ->entry as $entry ) {
$text = trim( $entry ->title);
$author = trim( $entry ->author->name);
$time = strtotime ( $entry ->published);
$id = $entry ->id;
echo "<p>Tweet from " . $author . ": <strong>" . $text . "</strong> <em>Posted " . date ( 'n/j/y g:i a' , $time ). "</em></p>" ;
}
return true ;
}
|
特殊说明,本文版权归 ning个人博客 所有带原创标签请勿转载,转载请注明出处.