Twitter widget that streams multiple accounts
I created a PHP/JavaScript widget that will stream multiple Twitter accounts for a friends website (see it in action at Brown Girl Magazine). It’s simple to setup. As of version 1.2.2 you will need to setup the widget again.
Requirements
- PHP 5.0
- PEAR – Cache_Lite v1.53 (It might work with newer or older versions but I haven’t tested it.)
- Javascript turned on
Instructions
- Install the PEAR package Cache_Lite. Most web hosts have an easy way of installing new PEAR packages. If you have issues with PEAR, create a directory called Cache within the directory you create in step 4, download Cache_Lite and put the contents (Lite.php and Lite directory) of Cache_Lite in it. Post any questions in the comments.
- Download TwitterWidget_1_2_3.zip. Unzip the contents to a temporary directory.
- Open Config.php and edit the configuration parameters. There is an explanation for each parameter.
- Create a directory where ever you like on your web server and upload all the files.
- Copy the following html and javascript into your website right before where the body tag (</body>) is closed.
<script type="text/javascript"><!-- var RPNetTwitterAttrs = { url: 'http://localhost/TwitterWidget/reboot/TwitterWidget.php' }; // --></script> <script type="text/javascript" src="TwitterWidget.js"></script>Update the url attribute to the path where you uploaded TwitterWidget.php.
You will also need to update the src=”TwitterWidget.js” attribute to point to where you uploaded the javascript file. For example, src=”http://yourwebsite.com/uploads/TwitterWidget.js”.
- Copy the following html into your website where you would like the widget to appear.
<div id='rpnetTWContainer'></div>
Editing the Look and Feel
There are two ways to change how the widget looks. The first is to add the CSS ids below to your stylesheet. The outline of the widget is as follows:
<div id="rpnetTWContainer"> <div id="rpnetTW"> <h2 id="rpnetTWTitle"></h2> <ul id="rpnetTWList"></ul> </div> </div>
The second way is to go into the createWidget() function in the RPNetTWView class in TwitterWidget.php and edit the html of the widget. Post any questions in the comments.
Remember
If you make changes to how the widget looks or you modify the Config.php after setting up the widget you will either need to wait until the cache expires or you will need to go into your cache directory and delete the cache file for changes to take effect.
Upgade Instructions
From 1.2.1 to 1.2.2.
- Record the changes made to Config.php.
- Start with Step 2 of the 1.2.2 instructions.
From 1.2.2 to 1.2.3.
- Overwrite all PHP, JavaScript, and text files except Config.php.
What it will not do
This widget will not worked on locked Twitter accounts.
Below is a screen shot of the widget with no formatting and with the Arthemia Wordpress theme. If using Wordpress the widget will conform to whatever theme you have unless you modify the CSS. Enjoy!
Change Log
Version 1.2.3
- Fixed issue with special characters.
Version 1.2.2
- Completely rewritten. Should make the widget load faster.
- Handle errors more gracefully.
- Filter by multiple hashtags.
- As of this version the widget is under the LGPL v3 License.
Version 1.2.1
- Fixed bug with unescaped characters.
Version 1.2
- Tweets are now cached.
Version 1.1
- Added an option for displaying user images.
Version 1.0
- Displays list of tweets from multiple users.
Old Versions
- Version 1.1 (Download) (Instructions)
- Version 1.2.1 (Download) (Instructions)
- Version 1.2.2 (Download) (Instructions are the same as on this page.)


April 14th, 2009 at 8:35 am
Hi!
I’m having some trouble getting this to work… I get the follwing error message:
‘this.$(…)’ is null or not an object
What can I do to correct this…?
April 14th, 2009 at 8:38 pm
Hi Andreas.
I’m going to need some more information in order to help you resolve the error. Would it be possible to give me the line number where the error occurs? What browser are you using? In addition to adding TwitterWidget.js to your website did you add the javascript code above before your tag. Also, did you add the html above to your website?
April 15th, 2009 at 2:11 am
The error occurs on line 38. I’m using IE8, but I get the same error with Firefox and Opera. I have added the javascript code exactly before the tag and the html-code to the page where I want the twitter output.
April 15th, 2009 at 3:36 am
I’m an idiot. Sorry. Solved it myself. I’m using a cms and I just added the script code to the default page. However, the script complaints if it can’t find the correct id’s in the html… So now I only include the script if the actual “twitter page” is shown.
May 10th, 2009 at 5:27 am
there is any possibility of incorporating the avatar?
May 10th, 2009 at 7:34 am
Absolutely. I’ll include user pictures in the next version.
May 10th, 2009 at 8:06 pm
thank you Ronald, I will be waiting for the next version.
May 25th, 2009 at 9:34 am
I am making my blogging software (because I am bored and I could use it as an independent study) and I wanted to added twitter widgets, this is perfect. Worked like a charm, thanks.
May 25th, 2009 at 10:09 am
I’m glad you liked it. I’ll be releasing a new version later today that will include an option for displaying user pictures.
May 25th, 2009 at 10:06 pm
[...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]
June 5th, 2009 at 10:09 am
Awesome widget, just what I was looking for, thanks.
A feature I would like to see is the count for each user. This would enable you to choose how many twitter updates to show for each user.
Thanks.
June 5th, 2009 at 10:44 am
Okay, It’s not working for me now, it’s not showing any Twitter posts… weird…
June 5th, 2009 at 9:47 pm
When it stopped showing tweets did you check to see if Twitter.com was down? I tried right now and didn’t see any tweets because twitter.com is “currently down for maintenance”.
June 8th, 2009 at 3:23 pm
ronak, thanks so much for these scripts, see them in action on the page i included…i was wondering however, if there was a way to only include tweets with a specific hashtag? i want a feed of specific users with one specific hashtag.
June 8th, 2009 at 9:05 pm
johnny, I will add that feature in the next version along with the feature Chris requested.
June 8th, 2009 at 11:17 pm
Chris, I think you may have hit the API limit(100 queries per hour) depending on how many accounts you’re pulling in tweets for you can hit this ceiling quite quickly
June 9th, 2009 at 8:36 am
could you create a loading bar while we wait for the script to load
June 9th, 2009 at 8:39 am
like the one in this script http://remysharp.com/2007/05/18/add-twitter-to-your-blog-step-by-step/ so i can add some content such as “cant wait follow me” or a loading bar image which would be cleared once the widget has fully loaded ? it would be great thanks very much for the script can i use this in comercial projects ?
June 9th, 2009 at 1:37 pm
awesome!
June 9th, 2009 at 5:22 pm
i’m realizing now that i’m going to have a big issue with the 100 requests limit as well…
June 9th, 2009 at 10:55 pm
coderz: The loading bar is a possibility. I want to keep this widget lightweight so the loading “bar” might just be text like you suggested.
johnny, Ben: The 100 requests per hour is definitely a limitation. I can have an option to limit the amount of requests per hour and cache the results. To do so would require some simple server side coding, but the widget would no longer only be Javascript. PHP/MySQL would be needed.
What does everyone think? Is that something you would want? Any other ideas?
I will get to all the feature requests as soon as possible.
June 10th, 2009 at 10:18 am
Hey, thanks guys.
Yeah, It seems to go down now and then when Twitter.com is online.
What do you mean by the API limit to 100 queries per hour. Does this mean the twitter feed can only be shown up to 100 times in an hour?
Thanks
June 10th, 2009 at 11:06 am
i think it would be great if you could add something like “can’t wait ? follow me” text which would be cleared once the widget has fully loaded so it doesn’t hang
thanks for the great script mate
June 10th, 2009 at 12:15 pm
the idea of cacheing the results and only updating the request every so often is what i was thinking. i have no problem with php/mysql…
thanks!
June 16th, 2009 at 4:43 pm
so, i took the time to learn enough javascript to filter the results in the widget by hashtag. remaining script problem for me will be the limited number of requests.
June 16th, 2009 at 8:04 pm
I am currently working on getting the caching of tweets implemented. I will have it ready by the end of the week if not sooner.
June 21st, 2009 at 9:12 pm
I was not able to work on the caching as much as I wanted to this week. I will have it out asap. Thanks for your patience.
June 26th, 2009 at 10:48 am
Hi there, this is great! I have been going out of my mind to find a widget that did just this for days. I was about to give up then finally found this
However I would appreciate a little help in terms of styling this widget by css. I have no knowlegde of php I’m afraid.
My problem is, each older tweet is pushed to the right in the list, and the list icon is showing, instead of all being in one nice neat continuous line. How do I go about making it as it appears in the screenshots above?
It’s probably something so obvious, but no harm in asking right?
June 26th, 2009 at 11:00 am
Sigh, it was something obvious aswell. There was already a styled ul in my CSS, sneaky little thing. lol, Sorry
July 5th, 2009 at 9:55 am
I’m using WP and I’m getting a blank on this. I don’t think I’m doing anything wrong. Help. http://www.teamwildoutdoors.com
July 5th, 2009 at 10:00 am
Oops, I just figured it out. I made a dumb mistake in calling the .js file.
July 5th, 2009 at 6:01 pm
Update: I created a cached version of the widget but I realized that with a little effort someone could take over the widget and make it display any user they wanted. Therefore, I am creating a php only version of the widget which should be out soon. In the meantime if enough people are interested I will release the unsecure version of the widget with caching.
July 11th, 2009 at 9:00 pm
Exactly what I’ve been looking for.
Would love a php version with caching as that’s the only thing missing for me.
I vote for an unsecure version while we wait for the php version.
Cheers
B
July 12th, 2009 at 5:45 pm
[...] The original idea came from our friends at Ronak Patel [...]
July 16th, 2009 at 9:38 pm
The widget now caches tweets. The downside is that there are a few more steps involved in setting up the widget. You guys know the drill. Post any questions, comments, or suggestions.
There are a few outstanding features to add in the next version:
1. Filtering by hashtag.
2. Loading text.
3. Custom counts for each user.
As before, I will get to those asap.
July 16th, 2009 at 9:40 pm
[...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]
September 13th, 2009 at 2:50 am
Ronak,
I had this working great until two days ago. Nothing really changed on the site that would have effected it but it just all of a sudden stopped showing the tweets. It generates the Title but then appears to break, but gives no error message, doesn’t stop the site from loading, and there’s nothing in the error logs.
The cache is dated back when it stopped working and hasnt picked up any new posts since then. The cache file is there, but for some reason it’s not being read now. I’ve tried deleting the cache file to see if it was the culprit and all it does is reappear exactly as it was before once I reload the page.
I’ve tried pulling out some new jQuery elements I implemented to see if they are conflicting but that didnt make a difference.
I’ve been staring at the code for hours now – it’s all pretty straightforward and everything was working fine. Any ideas? Any known conflicts or are you running into any problems with it also (pointing to maybe a Twitter change) ?
any help would be greatly appreciated – this is the only code / plugin I’ve found online to aggregate multiple accounts into one stream. It’s perfect for the site I have in development!
Thanks,
jeff
September 13th, 2009 at 3:00 am
Actually, an update here… the cache is in fact current and pulling from Twitter no problem. But for some reason the js is dying after generating the Title. …
September 13th, 2009 at 3:03 am
Ah Ha! Sorry for the flood here. Figured it out. something in one of the Tweets was killing it. a [ or a . or a “.. not really sure exactly what it was but I pulled the users out one by one and found the one with the offending tweets.
Any way to edit the code to strip out offending characters (or at least convert them to a non-offending character?)
September 13th, 2009 at 12:19 pm
Hi Jeff,
Absolutely. Thanks for spotting a problem. If you don’t mind could you send me the user with the problem character so I can test with it. Either reply here or send me a direct message on Twitter @RonakPatel.
September 13th, 2009 at 3:16 pm
Cool. Just sent you a @Reply on twitter with the info. (Couldn’t DM because you’re not following me).
November 11th, 2009 at 12:06 am
Ronak, for some reason the widget was working great and has since stopped working. This happened a couple of days ago. I’ve tried pulling users out, deleting the cache file, but nothing’s working. it’s not displaying any tweets. do you think this has anything to do with changes made to twitter? I’ve noticed it’s also not working on your example above at Brown Girl Magazine.
If you have any suggestions or fixes, please let me know – if not and you’ve stopped developing this plugin altogether, please also let me know so I can pull it out and loook for another solution.
thanks for your hard work and time on this!
Jeff
@jeff_uprising
November 11th, 2009 at 8:52 am
Hey Jeff. I haven’t worked on the widget in a while but I haven’t stopped developing for it. I will take a look today. Thanks for letting me know.
November 11th, 2009 at 8:57 pm
Ronak, a little while ago you sent me a new version of the widget because special characters were breaking it. I believe that’s still happening and I believe I’ve isolated the characters to one of the following: ‘[ ] ( ) : / .’
Any help would be greatly appreciated. we’re using the plugin here and every now and then it’s going blank:
http://www.urb.com
thanks!
Jeff
@jeff_uprising
November 11th, 2009 at 10:51 pm
Jeff, I think I fixed the problem. I emailed you an updated copy of Data.php. Let me know if it works and I’ll make an official release. Thanks.
November 12th, 2009 at 11:08 pm
[...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]
November 13th, 2009 at 9:18 pm
Damn dude, you’re hardcore! Looks cool – wish I had time for side projects like this.
November 22nd, 2009 at 6:15 pm
Hey,
I’ve just updated to the most recent version but I can’t seem to get it working. I’m not able to get anything from twitter shown. Everything in my files looks okay, any ideas?.
Thanks.
November 29th, 2009 at 6:44 pm
Chris, does the cache file have text in it, or is it empty?
December 9th, 2009 at 4:28 am
Hello,
I found what could be the answer to my Twitter Widget dilemma in yours, but am having problems getting it to show any content. It looks to be an issue with my Pear and Cache/Lite.php set up as this is the error I receive when trying to view Data.php in my browser:
—————————-
Warning: require(Cache/Lite.php) [function.require]: failed to open stream: No such file or directory in /home/staticka/droid.statickadesign.com/TwitterWidget/Data.php on line 3
Fatal error: require() [function.require]: Failed opening required ‘Cache/Lite.php’ (include_path=’.:/usr/local/php5/lib/php:/usr/local/lib/php’) in /home/staticka/droid.statickadesign.com/TwitterWidget/Data.php on line 3
—————————-
It seems I need to change the include_path – (include_path=’.:/usr/local/php5/lib/php:/usr/local/lib/php’) – but am unsure where. Here is my config file:
—————————-
—————————-
And in my footer:
—————————-
—————————-
I have even made sure to install the files it was looking for inside the called directories:
http://droid.staticka.com/Cache/
Please let me know what I need to present to you in helping resolve my issue. I’m not entirely php savvy, but can work to getting you what you need.
Thanks in advance.
December 15th, 2009 at 10:17 pm
Have you tried placing the Cache directory under /home/staticka/droid.statickadesign.com/TwitterWidget/?
January 5th, 2010 at 4:41 pm
Hi Ronak, how are you doing with adding in the filter by hashtag feature? There is currently NO widget on the internet that does this – I find it a bit weird as I would have thought this is quite a desirable feature! Do you know why this is?
Cheers,
Dave x
January 5th, 2010 at 8:59 pm
Dave,
I recently rewrote the widget and will be including hashtag filtering in that. The rewrite is currently in testing and will be released soon.
January 10th, 2010 at 9:24 pm
I have hashtag filtering working. Before I release it does anyone need multiple hashtag filtering?
January 11th, 2010 at 9:28 pm
[...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]
January 11th, 2010 at 9:42 pm
Version 1.2.2 of Twitter Widget has been released. It has been rewritten to hopefully make the widget load faster and it also includes filtering by multiple hashtags.
January 18th, 2010 at 4:15 pm
Hi,
Love the plugin- clear installation instructions, and works great. Just one problem- apostrophes (‘) are not coming through properly in the widget. They’re being rendered as \’ which is a bit weird.
Any thoughts on how to fix this? Thanks.
January 18th, 2010 at 10:26 pm
Mark,
Thanks for pointing that out. It’s been fixed. Upgrade instructions are in the post.
January 18th, 2010 at 10:36 pm
[...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]
January 21st, 2010 at 2:48 pm
Thanks for the quick update Ronak. Very impressed!
February 4th, 2010 at 8:06 pm
Hi there,
Very excited to use this plugin… been looking for something to handle multiple twitter accounts for awhile now. I have PEAR and Cache_Lite installed, and installed the widget (and was getting error messages, so I created the Cache folder and moved the Cache_Lite files into that), but now I’m getting the message: Cannot save to cache.
Any ideas would be much appreciated.
Thanks again for the work.
February 4th, 2010 at 8:27 pm
Andrew,
In the Config.php there is a parameter for the name of the directory where the cached tweets will be saved. Was this created in the directory where you installed the widget?
February 5th, 2010 at 12:34 pm
Ronak,
No new directory was created, but maybe the cache just needed to expire? In any case, the message has changed now to “Tweets cannot be decoded from feed.”
Andrew
February 5th, 2010 at 1:13 pm
That directory needs to be created manually otherwise there is no place for the cache to be saved.
February 5th, 2010 at 1:17 pm
Okay, I figured it out. Or at least, got it working.
Thanks a bunch, this is a great piece of work!