Small library for fetching and formatting Twitter feeds (With cache!) |
[eluser]Starovich[/eluser]
I needed to see a Twitter feed on a homepage I was developing and looked into what I could find that was compatible with CodeIgniter. Unfortunately, many libraries were either outdated or overly complex. Some of them didn't utilise oAuth (An authentication system Twitter will require after June 2010) and others required Curl, which my hosting provider does not have. Then I figured that since I would only need to get feeds, not update twitter status from inside my application, I could use a RSS library to fetch the regular RSS that Twitter provides for every user. SimplePie worked fine, and here we are. So if you are interested in -only- fetching feeds and displaying them on a page, this is for you. Prequisites: - Simplepie for CodeIgniter, get it here: http://www.haughin.com/code/simplepie/ (and put it in your /libraries/ folder) - A database configured in CI, must support TRUNCATE command. (MySQL works fine for this, other DB's should too.) Optional: - Cron, or another way of scheduling the cache update. Download: Zip file is attached to post! Installation: You will need to upload the two files, Twitter_rss.php and twitter_rss_queries.php to the appropriate folders. The directory structure is intact so you should be able to drop the folders directly into your config. Also don't forget to fetch Simplepie.php, look at Prequisites above. Then create the table we will use to store the tweets, 'media_tweets' for which the structure you will find in create.sql inside the downloaded zip archive. Code: SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; You will need to use some kind of tool (like phpMyAdmin) or use a console for this. Now we're all set, using the library from any controller works like this: Code: $this->load->library('twitter_rss', array('number_of_items' => 3, 'feed_url' => 'http://twitter.com/statuses/user_timeline/12889082.rss')); The content of $data['my_formatted_rss'] will be: Code: <div id="content-rss"> There are no additional options for the library than in the example. If there will be popular demand I could add styling options etc, but the library code clocks in at only 150 rows so it shouldn't be too hard to add if needed. This is my very first library, so if you spot something that isn't correct, let me know!
[eluser]nolastan[/eluser]
Thanks, I found this very helpful. One note: in Twitter_rss.php: Code: /* parses the DB output of the tweets */ Thanks again, Stan
[eluser]nolastan[/eluser]
One more issue... Code: /* kindly stolen from: http://codeigniter.com/wiki/Twitter-Tweet_Parser/ */ |
Welcome Guest, Not a member yet? Register Sign In |