2011
If you have your own blog which is PHP powered, you can show your tweets on twitter by using PHP easily. According to GET Search Twitter API documentation and Using Search documentation, we can do any search for tweets related to any keyword provided. The resource URL for searching is:
http://search.twitter.com/search.format
where format is the format we would like to get. It could be rss, atom, or even json. The Twitter search API is very powerful, even you can get any tweets which is posted by someone near you.
Right to example, I have used this API to show any recent tweets related to me, which is containing the word "aryoxp". I need it in RSS format so I can process it further in PHP by using RSS parser. So the resource URL would be as simple as:
http://search.twitter.com/search.rss?q=aryoxp
Note that I did not including the "@" character to the query string, because I would like to get all posts related to aryoxp not only posts by @aryoxp or have @aryoxp mentioned. You can get more complete information about parameters used in the query string here.
Try to copy and paste the above resource URL to your browser. The twitter API then will return all of matched post related to your search.
Fetching The Resource URL
To fetch the RSS by using PHP, you will need the PHP cURL library. If you're using public commercial web hosting service which provides PHP support, usually the cURL library is already installed and ready for you to use. For more information about cURL installation, read it here. You don't know whether cURL is enabled or not on your PHP? Check it out, by using the following world famous simple oneliner PHP code. If it's already installed, then it will show the installed cURL library information.
<?php phpinfo(); ?>
The following PHP code is used to fetch the twitter RSS (in XML format) using PHP cURL:
<?php
$keyword = "aryoxp";
$timeout = 0;
$url = "http://search.twitter.com/search.rss?q=".$keyword;
//initialize cURL
$ch = curl_init();
//Set cURL options
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
// execute the cURL to fetch the RSS
$rss=curl_exec($ch);
curl_close($ch);
?>
...
<item>
<title>Starting a project: caching my #twitter posts and other related.</title>
<link>http://twitter.com/aryoxp/statuses/101411289137553410</link>
<description>Starting a project: caching my <a href="http://search.twitter.com/search?q=%23twitter" title="#twitter" class=" ">#twitter</a> posts and other related.</description>
<pubDate>Wed, 10 Aug 2011 21:55:10 +0000</pubDate>
<guid>http://twitter.com/aryoxp/statuses/101411289137553410</guid>
<author>aryoxp@twitter.com (Aryo)</author>
<media:content type="image/jpg" height="48" width="48" url="http://a3.twimg.com/profile_images/1325498499/foto_normal.jpg" />
<google:image_link>http://a3.twimg.com/profile_images/1325498499/foto_normal.jpg</google:image_link>
<twitter:metadata>
<twitter:result_type>recent</twitter:result_type>
</twitter:metadata>
</item>
...
04:35 AM
Buat twitter JSON lebih irit benwit yo. Enaknya lg langsung si browser client yg decode. Jadi server melayani sebanyak mungkin static files. Seicrit dynamic pages Hehehe good post bro! Aktifis FPS (front pembela server)
Write Your Comments
* Your email is required to submit this form, and it will not be published or shared without your consent. We use your email address to show your avatar picture profile from Gravatar. Don't have one? Then sign up to gravatar and create your own here.
We also filters your comment against SPAM because we hate SPAM as much as you do. If your comment is recognized as SPAM then it will be moderated, otherwise it will shows up immediately.
842 Hits