简体   繁体   中英

How to display tweets from twitter using Hash tags by PHP+MySQL

I am looking on to develop a php page, which shows tweets for a couple of hashtags, Suppose #apple, #iphone will display all the recent tweets for that Hashtags.

I am looking to use this with PHP and MySQL. Dont know how to use Twitter stream API.

Do i need to create a cache and store it into MySQL or Can i display the recent 100 tweets on a particular hashtag. Also I heard some limitations are there for twitter api to be called.

Using the twitter api atom feed you can retrieve by hashtag with the following url,

http://search.twitter.com/search.atom?q=%23apple&rpp=100

this returns an xml based response so something like the below could read it:

$feed = "http://search.twitter.com/search.atom?q=%23apple&rpp=100";
$xml = simplexml_load_file($feed);
foreach($xml->entry  as $id => $entry)
{
   //do what you want here,
   //some (definitely not all) available values are
   $linkToTweet = $entry->link[0]["href"];
   $linkToAvatar = $entry->link[1]["href"];
   $timestamp = $entry->updated;
   $tweet = $entry->content;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM