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

  1. 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.
  2. Download TwitterWidget_1_2_3.zip. Unzip the contents to a temporary directory.
  3. Open Config.php and edit the configuration parameters. There is an explanation for each parameter.
  4. Create a directory where ever you like on your web server and upload all the files.
  5. 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”.

  6. 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.

  1. Record the changes made to Config.php.
  2. Start with Step 2 of the 1.2.2 instructions.

From 1.2.2 to 1.2.3.

  1. 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

Tags: , , , ,

66 Responses to “Twitter widget that streams multiple accounts”

  1. Andreas Says:

    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…?

  2. ronak Says:

    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?

  3. Andreas Says:

    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.

  4. Andreas Says:

    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.

  5. cristián Says:

    there is any possibility of incorporating the avatar?

  6. ronak Says:

    Absolutely. I’ll include user pictures in the next version.

  7. cristián Says:

    thank you Ronald, I will be waiting for the next version.

  8. Mohan Ram Says:

    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. :)

  9. Ronak Says:

    I’m glad you liked it. I’ll be releasing a new version later today that will include an option for displaying user pictures.

  10. RonakPatel.Net » Blog Archive » Twitter Widget 1.1 Says:

    [...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]

  11. Chris Says:

    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.

  12. Chris Says:

    Okay, It’s not working for me now, it’s not showing any Twitter posts… weird…

  13. Ronak Says:

    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”.

  14. johnny Says:

    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.

  15. Ronak Says:

    johnny, I will add that feature in the next version along with the feature Chris requested.

  16. Ben Says:

    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

  17. coderz Says:

    could you create a loading bar while we wait for the script to load

  18. coderz Says:

    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 ?

  19. johnny Says:

    awesome!

  20. johnny Says:

    i’m realizing now that i’m going to have a big issue with the 100 requests limit as well…

  21. Ronak Says:

    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.

  22. Chris Says:

    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

  23. coderz Says:

    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

  24. johnny Says:

    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!

  25. johnny Says:

    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.

  26. Ronak Says:

    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.

  27. Ronak Says:

    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.

  28. Jenna Says:

    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?

  29. Jenna Says:

    Sigh, it was something obvious aswell. There was already a styled ul in my CSS, sneaky little thing. lol, Sorry :)

  30. Cory Glauner Says:

    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

  31. Cory Glauner Says:

    Oops, I just figured it out. I made a dumb mistake in calling the .js file.

  32. Ronak Says:

    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.

  33. Brenden Says:

    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

  34. How to add a Twitter Stream to Pligg Says:

    [...] The original idea came from our friends at Ronak Patel [...]

  35. Ronak Says:

    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.

  36. RonakPatel.Net » Blog Archive » Twitter Widget 1.2 Says:

    [...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]

  37. Jeff Nicholas Says:

    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

  38. Jeff Nicholas Says:

    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. …

  39. Jeff Nicholas Says:

    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?)

  40. Ronak Says:

    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.

  41. Jeff Nicholas Says:

    Cool. Just sent you a @Reply on twitter with the info. (Couldn’t DM because you’re not following me).

  42. Jeff Nicholas Says:

    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

  43. Ronak Says:

    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.

  44. Jeff Nicholas Says:

    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

  45. Ronak Says:

    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.

  46. RonakPatel.Net » Blog Archive » Twitter Widget 1.2.1 Says:

    [...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]

  47. Elton Says:

    Damn dude, you’re hardcore! Looks cool – wish I had time for side projects like this.

  48. Chris Says:

    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.

  49. Ronak Says:

    Chris, does the cache file have text in it, or is it empty?

  50. Staticka Says:

    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.

  51. Ronak Says:

    Have you tried placing the Cache directory under /home/staticka/droid.statickadesign.com/TwitterWidget/?

  52. Dave Says:

    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

  53. Ronak Says:

    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.

  54. Ronak Says:

    I have hashtag filtering working. Before I release it does anyone need multiple hashtag filtering?

  55. RonakPatel.Net » Blog Archive » Twitter Widget 1.2.2 Says:

    [...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]

  56. Ronak Says:

    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.

  57. mark c Says:

    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.

  58. Ronak Says:

    Mark,

    Thanks for pointing that out. It’s been fixed. Upgrade instructions are in the post.

  59. RonakPatel.Net » Blog Archive » Twitter Widget 1.2.3 Says:

    [...] http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/ [...]

  60. mark c Says:

    Thanks for the quick update Ronak. Very impressed!

  61. Andrew Larimer Says:

    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.

  62. Ronak Says:

    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?

  63. Andrew Larimer Says:

    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

  64. Ronak Says:

    That directory needs to be created manually otherwise there is no place for the cache to be saved.

  65. Andrew Larimer Says:

    Okay, I figured it out. Or at least, got it working. :-) Thanks a bunch, this is a great piece of work!

  66. Mark C Says:

    Hi Ronak,
    was using the plugin for a while there but had to stop using it. I had it set to pull tweets from four users from specific hashtags. Tweets seemed to ‘expire’ randomly, so if tweets weren’t posted for a few days the widget would appear empty. Is there any reason for this, and can it be resolved?

    I want to start using the plugin again as apart from this it’s excellent.
    Cheers.

Leave a Reply