AjaxTwits – Load Tweets on your website with AJAX

102

Twitter is an amazing service to keep in touch with everyone on the Internet. It’s easy, fast and there are a lot of Twitter applications.

I came up with the idea to Ajaxify (is that even a word?) the tweets on my website. As you can see, it’s on the right, below the last.fm recently played. It’s called AjaxTwits!

This article will show you how to use AjaxTwits and how to install it on your website.

ajaxtwits

Download
AjaxTwits zip-archive
Example
AjaxTwits in action!

Example of AjaxTwits is located at: http://www.gayadesign.com/scripts/ajaxtwits/

AjaxTwits and all it’s files can be downloaded here: http://www.gayadesign.com/scripts/ajaxtwits/ajaxtwits.zip or the old version

Update notice:

There were a few things going from in the AjaxTwits class which have been fixed. Some tweets seems to make AjaxTwits stop working. I also included the date in the Javascript code.
Download the new zip to gain access to the improved code.

If you have an installation of AjaxTwits on your site you can replace the AjaxTwits.php class with the file from the new zip. The Javascript has changed to, but it’s not necessary to change.

What does AjaxTwits do?

  • Load a twitter timeline and / or the replies of a twitter account
  • Cache the results so you don’t stress the twitter servers
  • Avatar finder (auto update if user uploads a new one)
  • Load multiple timelines / replies from different accounts
  • AJAX support with JSON option or XML
  • Front-end Javascript output
  • Automatic hyperlink finder and @username linking
  • Easy to adjust to your likings

Why AjaxTwits?

The problem with loading twitter on the server side part of your website is that it will slow down the load time massively. Which means your pages will load pretty slow.

This is because of the use of external feeds and services, it takes some time to load them. The server will read the XML and RSS feeds very quickly, but PHP still has to load the files from the Twitter servers.

AjaxTwits keeps the load time separate from your website, meaning it will load after your page is loaded and not effecting the user experience. Yes, the services still need to be loaded. But the loading is done afterward.

The caching of results prevents the service to stop loading the feeds. Twitter has a build in limit of requests, so be gentle on their servers.
This also helps to load AjaxTwits very quickly and output tweets in a few milliseconds!

The twitter timeline is also limited to only your tweets and not those of other people. That’s why AjaxTweets also supports search queries performed on http://search.twitter.com/. AjaxTwits has an easy build-in option to get all the reply messages of a user and mix them into the timeline.

What do I need?

  • PHP with JSON and SimpleXML support (PHP 5.2.0 or greater)
  • A Twitter account to consume or a Twitter account of someone else
  • An FTP client to upload contents to the server

How to install:

AjaxTwits is fairly easy to install, the following steps will enable AjaxTwits on your website!

Step 1: Download and upload AjaxTwits

Download AjaxTwits here: http://www.gayadesign.com/scripts/ajaxtwits/ajaxtwits.zip.

Unzip the contents and upload them to your web server. Anywhere you’d like!

Step 2: Adjust the request file

In the “AjaxTwits” folder you just uploaded is a file called “AjaxTwitsRequest.php” and “AjaxTwitsUpdate.php“. Open this file in an editor.

	//include AjaxTwits and create an object
	include('AjaxTwits.php');
	$ajaxTwits = new AjaxTwits;

	//set the cache to a writable folder, to save xml files
	$ajaxTwits->cachefolder = "AjaxTwits/cache";
	//the amount of minutes the feed is cached
	$ajaxTwits->cacheTime = 15;

	//the amount of items you'll show
	$ajaxTwits->itemCount = 6;

	//add your twitter account feeds
	$ajaxTwits->addTimeline("gayadesign");
	$ajaxTwits->addReplies("gayadesign");

	//this will output the information, JSON is for the Javascript application
	$ajaxTwits->outputFeed("json");

Adjust the following line to your likings:

$ajaxTwits->cachefolder = “AjaxTwits/cache”;
This is the folder where the XMLs will be cached. Enter the folder starting in the root of your website. So if you have AjaxTwits installed in /blog/AjaxTwits/ the cache folder should be blog/AjaxTwits/cache.

$ajaxTwits->cacheTime = 15;
The amount of minutes the XML should stay on your server before it will be refreshed. This means that every 15 minutes the timeline will be updated on your site. Adjust to your likings.

$ajaxTwits->itemCount = 6;
The amount of items you want to output on your website.

$ajaxTwits->addTimeline(“gayadesign”);
Load the public timeline of the given username.

$ajaxTwits->addReplies(“gayadesign”);
Load the replies of the given user. Every tweet on Twitter containing @gayadesign in this case.

Upload the adjusted file to your server if needed.

Step 3: Make the cache folder writable

Explore the server contents with an FTP client and make the cache folder (default: AjaxTwits/cache) writable using chmod 777.

This is for saving XML on the server.

Step 4: Include AjaxTwits on your webpage

In the header (<head>) of your HTML add the following code:

<script src="js/AjaxTwits.js" type="text/javascript"></script>
<link href='css/AjaxTwits.css' rel='stylesheet' type='text/css' />

This will load the necessary Javascript + the styling of the widget.

Step 5: Get the HTML of the widget ready

Add this to your HTML on the place you want to include the widget:

<ul id='AjaxTwits'>
	<li id='AjaxTwitsLoader'>
		<em>Loading tweets</em>
	</li>
</ul>
<script type="text/javascript">
	getAjaxTwits("AjaxTwits/AjaxTwitsRequest.php", 6);
</script>

The tweets that are loaded will be inserted into the unordered list with id AjaxTwits. The list item AjaxTwitsLoader will be deleted.

Adjust getAjaxTwits(“AjaxTwits/AjaxTwitsRequest.php”, “AjaxTwits/AjaxTwitsUpdate.php”, 6); to your preferences.

The first parameter is the location of the AjaxTwitsRequest.php file. The second parameter is the location of the AjaxTwitsUpdate.php file. The third parameter is the amount of items to show.

Conclusion:

That’s all you have to do! Not that much right?

You can adjust the CSS and mess around with the Javascript if you like.

Hope this will help you create a nice Twitter widget on your website.

Articles like this one

If you liked this article you can add this post to:


 

97 Comments

  1. Lyndsay said: March 26, 2009 at 3:28 pm | Permalink

    You are brilliant <3

    I’m so thankful for Twitter that I’ve found your site & many other talented web programmers like you!


  2. Louis Gubitosi said: March 26, 2009 at 3:55 pm | Permalink

    This is a great tutorial! keep up the good work!


  3. Gaya said: March 26, 2009 at 4:12 pm | Permalink

    Thank you both for the kind comments =)

    Hope you like the script and get it to work well on your sites.


  4. Ryan said: March 28, 2009 at 5:29 pm | Permalink

    For the last freakin time, Twitter updates are TWEETS, NOT ‘TWITS’.


  5. Gaya said: March 28, 2009 at 5:48 pm | Permalink

    Yeah, I though that half way through. First it was called AjaxTwitter. But AjaxTwits had a better ring to it. And I use the word tweets in the tut. Anyway, hope you still liked it ^^


  6. SIEB said: March 28, 2009 at 8:10 pm | Permalink

    GAYA, you are the master!


  7. Gaya said: March 29, 2009 at 2:21 pm | Permalink

    Thnx Sieb =D


  8. Ariyo said: March 30, 2009 at 1:15 am | Permalink

    You are GREAT. Thanks


  9. Freek said: March 30, 2009 at 2:17 pm | Permalink

    I did exactly what the tutorial said but, I only get a screen with a black rectangle and the text: “Loading tweets”.

    (http://www.freekplak.net/twitter/)

    I guess I did something wrong or my ftp doesn’t suport the scripts or so anyone an idea what I could have done wrong?

    did chmod 777 and editted cachefolder to: twitter/AjaxTwits/cache

    Thanks in advance, would be great if it works :)


  10. Gaya said: March 30, 2009 at 2:43 pm | Permalink

    Hey Freek, check out your inbox =)


  11. Gaya said: March 30, 2009 at 3:46 pm | Permalink

    Who ever gets the T_OBJECT_OPERATOR error: Your PHP version is too low, sorry!


  12. Justin said: April 14, 2009 at 8:23 pm | Permalink

    Thanks for the great ajax script, Gaya!

    I’m having some trouble getting it to work though.

    I got the same black rectangle as Freek… got any advice on this, Gaya?


  13. Gaya said: April 14, 2009 at 9:47 pm | Permalink

    Hey Justin,

    Thanks for the comment! If you can give me a URL I can look into it =)


  14. Justin said: April 14, 2009 at 10:57 pm | Permalink

    Yes.

    => http://www.traveluseek.com


  15. Gaya said: April 14, 2009 at 11:04 pm | Permalink

    Looks like it is giving back an empty response.
    Try enabling errors on the AjaxTwitsRequest page for more info.


  16. Justin said: April 15, 2009 at 1:38 am | Permalink

    I tried using the following code in my .htaccess file for debugging:

    php_flag display_errors on

    Still no reporting…


  17. Justin said: April 15, 2009 at 2:11 am | Permalink

    If you meant the AjaxTwits Page, then I just changed “var $debug = false;” to true.

    But, still nothing…


  18. Gaya said: April 15, 2009 at 8:14 am | Permalink

    Hey Justin,

    Try the following code in top of the AjaxTwitsRequest file:

    ini_set(“display_errors”,”2″);
    ERROR_REPORTING(E_ALL);

    Setting it in the ini file won’t work in most situations.


  19. Justin said: April 15, 2009 at 6:04 pm | Permalink

    Doesn’t seem to solve it either…


  20. Gaya said: April 15, 2009 at 10:15 pm | Permalink

    Almost looks like it can’t find any feed info because it’s not erroring in any way. Can’t do much more from here, I’d have to look in the source.


  21. Justin said: April 15, 2009 at 11:15 pm | Permalink

    Ok. Thanks for the support on the scripting.

    …your script is cool anyway!


  22. Gaya said: April 16, 2009 at 12:08 am | Permalink

    Thanks do come back for more =)! (Make sure you entered the username parameters right. Could be causing the empty response.)


  23. ray said: May 4, 2009 at 7:36 pm | Permalink

    Hi’ I also downloaded ajaxtwits and tried installing it onto my website but I’m experiencing the same thing like Justin and Freek. I did everything in the tutorial but all I get is a blackbox that says “loading tweets”

    Could there be something else if 2 other people are experiencing the same problem in trying to get this work?


  24. Gaya said: May 4, 2009 at 10:07 pm | Permalink

    Hey Ray!

    Freek’s problem was that the PHP version was too old. And Justins problem I couldn’t look into.
    If you send me a link through the contact form, I could that a look for you :)

    Thanks for checking my blog :)


  25. Jamie said: May 7, 2009 at 11:52 pm | Permalink

    I’m also having trouble getting the script to work.

    On the page where the widget should be loading, I get:

    Loading tweets getAjaxTwits(“js/ajaxtwits/AjaxTwits/AjaxTwitsRequest.php”, 6);

    Any thoughts, Gaya? I sure hope we can make this work…this script is brilliant!


  26. Gaya said: May 8, 2009 at 11:02 am | Permalink

    Hi Jamie,

    If you can send me a link to the page I can check it out for you.

    You can also see the response using Firebug.


  27. Bobby said: May 26, 2009 at 9:58 pm | Permalink

    I would like to know if this script will support multiple feeds and intertwine/combine them chronologically. The introduction says “Load multiple timelines / replies from different accounts,” but I’m not sure if that’s the same thing as I just described. I’ve been using this script to combine feeds:

    http://www.aftergeek.com/2008/02/combine-multiple-twitter-feeds-on.html

    But I’ve been desperately looking for a combined-feed ajax solution that won’t hang my site. Thanks.


  28. Gaya said: May 26, 2009 at 10:48 pm | Permalink

    Hey Bobby! This script combines the feeds and sorts them according to time. So the tweets get mixed and laid out over time :) Hope this answers your question. Cheers!


  29. Jarand F. Millett said: May 26, 2009 at 11:39 pm | Permalink

    Hi!

    I get this error, when trying to use the script:

    Feil: unterminated regular expression literal
    Kildefil: http://jfm.no/ny/template/ajaxtwits/js/AjaxTwits.js
    Linje: 38, kolonne: 5
    Kildefil:

    The XML is here: http://jfm.no/ny/template/ajaxtwits/AjaxTwits/AjaxTwitsRequest.php

    The code i`m using to get the last tweet is:

    Loading tweets

    getAjaxTwits(“http://jfm.no/ny/template/ajaxtwits/AjaxTwits/AjaxTwitsRequest.php”, 1);

    Where have i gone wrong?


  30. Gaya said: May 27, 2009 at 12:36 am | Permalink

    Hi Jarand. That looks like a Javascript error. Seems like you are trying to push XML to your Javascript. This example is meant to only consume JSON, so try outputting JSON in the AjaxTwitsRequest.php file.
    Hope this helped you :) Good luck!


  31. Jarand F. Millett said: May 27, 2009 at 12:41 am | Permalink

    Thanks for the answar. I tought i could change JSON to XML? My server dont support JSON. Does that mean that I cant use this script?


  32. Jarand F. Millett said: May 27, 2009 at 12:41 am | Permalink

    Take a look at this file when i have change it to json: $ajaxTwits->outputFeed(“json”);

    http://jfm.no/ny/template/ajaxtwits/AjaxTwits/AjaxTwitsRequest.php


  33. Gaya said: May 27, 2009 at 9:22 am | Permalink

    Ahw, that is too bad :(
    There are some alternatives to this. For one you can try to read XML in Javascript instead of the JSON method I use.


  34. Bobby said: May 27, 2009 at 4:29 pm | Permalink

    Gaya — Thank you. This works beautifully, including for multiple feeds. Excellent work!

    I can’t find where the “loading” text is located. I’d like to edit it and perhaps even replace it with a spinner or animated gif.

    Thanks again!


  35. Gaya said: May 27, 2009 at 4:31 pm | Permalink

    @Bobby:
    It’s in the HTML :) for you to configure. Glad you liked the script!


  36. Bobby said: May 27, 2009 at 4:33 pm | Permalink

    Nevermind my comment/question above. It’s in the index file. Duh. Thanks!


  37. Bobby said: May 27, 2009 at 4:40 pm | Permalink

    OK. I swear I’m not an idiot given my past two posts. But these are stumping me:

    (1) How do I hide the avatar? I tried remming out the avatar output in ajaxtwits.php but I still get it. Can it be that they’re still cached and will eventually clear?

    (2) Is there a way to get a relative time output per tweet (posted x mins/hrs/days ago)?


  38. miker said: May 27, 2009 at 5:29 pm | Permalink

    bobby’s ? for posted x mins ago reminds me ifno — can line code be added for outputtting feedname in front like so — feedname: [feed] [post x ago]


  39. SanJoSharks said: May 27, 2009 at 5:47 pm | Permalink

    @Bobby: U were able to get multiple feeds? How? I thought this would work in AjaxTwitsRequest:

    $ajaxTwits->addTimeline(“x-feed”);
    $ajaxTwits->addTimeline(“y-feed”);
    $ajaxTwits->addTimeline(“z-feed”);

    But it just hangs up the script and it gets stuck at loading…. How’d you do it? Has anyone else done it?


  40. Bobby said: May 27, 2009 at 5:52 pm | Permalink

    @SanJoSharks: I entered two feeds exactly as you wrote, and it works for me. Not sure the problem — but as you can see, I’m no expert at all!


  41. Gaya said: May 27, 2009 at 6:01 pm | Permalink

    @Bobby, @miker:
    You can change this in the Javascript by adding: ans.item[i].date somewhere. You did it to my own feeds. You can also remove the avatars in the Javascript (It’s needed or it will error).

    @SanJoSharks:
    I’ve experienced some problems with AjaxTwits myself. I’ve upgraded the script and will share it with you later (maybe tonight). Hope that will fix some things.


  42. Bobby said: May 27, 2009 at 6:35 pm | Permalink

    Thanks for the quick response, Gaya! Looks like there’s been a flutter of interest suddenly.

    As for the date, if I wanted the Twitter URL to be linked to the relative date, this obviously doesn’t work:

    a.className = “twitter-link”;
    a.innerHTML = “ans.item[i].date”;

    What’s the proper syntax? Also, miker’s question sounds interesting: Is there an ans.item[i].date equivalent variable/call for feedname that can be used to precede a post like he wrote? That’d be awesome!


  43. Gaya said: May 28, 2009 at 8:45 am | Permalink

    Yeah, nice of people to have interest all of the sudden :)
    you don’t need the quotes to insert the date.

    a.innerHTML = ans.item[i].date;

    will do.

    For the feed name: there is nothing I have for that. sorry.


  44. Gaya said: May 28, 2009 at 10:19 am | Permalink

    There is an update notice on this post. A new version is available for download.
    Go to the top of the post to download. (Lots of fixes!)


  45. Andy Feliciotti said: May 28, 2009 at 4:25 pm | Permalink

    Great stuff


  46. Bobby said: May 28, 2009 at 4:44 pm | Permalink

    Thanks for the help with the date. And, by trial and error, I found how to output the user name. Right now, I’m using this:

    a.innerHTML = “[posted " + ans.item[i].date + ” by ” + ans.item[i].user + “]”;

    That outputs “[posted DATE by USER]“!

    What I would really like to do, and I hope someone can help (I’m a JS idiot but know HTML/CSS well) is how to edit the js to accomplish an output like below. (Sorry, but don’t know how to post styled text in this comment box.)

    underlinebeginUSERunderlineend: POST [posted urlbeginDATEurldend]

    If anyone can show me how to add the underlining, colon, and brackets (without linking the brackets), I would GREATLY appreciate it.

    Sorry about all the detail questions, but I can’t wait to get this script live in my site!


  47. Bobby said: May 29, 2009 at 8:18 pm | Permalink

    Answering my own question….

    To get this output:

    *user*: *message* [posted *2009/05/25*]

    I used the following code:

    var message = hyperlinks(ans.item[i].description);
    message = twitter_users(message);

    li.innerHTML += “” + ans.item[i].user + “: “;
    li.innerHTML += message + ” [";

    var a = document.createElement("A");
    a.href = ans.item[i].url;

    a.className = “twitter-link”;
    a.innerHTML = “posted ” + ans.item[i].date;

    li.appendChild(a);

    li.innerHTML += “]”;

    twitter.appendChild(li);


  48. El Pero Grande said: May 31, 2009 at 3:23 pm | Permalink

    Great work here! Goodonya, Mr. Gaya, sir.

    Just put in site last nite and voila ,….two feeds working well together…until twitter went down for fordy minyutes. During that time I have loading message whole time on mozilla and firefox but a friend beta testing said in ie6 (blech) he got a timeout error screen.

    so my question is can there be timeout control added if twits dont load within certain time it gives ‘twitter is down’ message?


  49. Gaya said: May 31, 2009 at 8:30 pm | Permalink

    @Bobby:
    Seems like you’ve been busy :D! Good! I love seeing other people trying to get the best out of code you didn’t write yourself. I’ll reply to your mail very soon :)

    @El Pero Grande
    Gracias signor! About the timeout: Good thinking! If I am going to implement the timeout thing, I’ll let you know :) Glad you liked the script!


  50. mikeyp said: June 2, 2009 at 6:43 am | Permalink

    i’ve noticed that a couple times a day the script gets stuck at “loading”. clearing the cache makes it work immediately. does that suggest a known problem, and is there anything i can do to fix it? thx.


  51. Gaya said: June 2, 2009 at 8:38 am | Permalink

    @mikeyp: There must be something wrong with the cached file. There is an error output of the PHP if you inspect the response from the AJAX request. You can inspect this with Firebug or a tool of that kind. Maybe you can see more there.


  52. Bobby said: June 5, 2009 at 5:24 pm | Permalink

    Hey, Gaya. Just wanted to follow up on that question re assigning names to feeds. If the user (ans.item[i].user) is A for example, substituting/returning X. That way, a non-obvious feed name can be attributed to someone in a more obvious way. Thanks.


  53. Gaya said: June 5, 2009 at 5:56 pm | Permalink

    Hey Bobby,

    I’ve been thinking. The best way (I think) you can solve this is by adjusting the AjaxTwits class. This would take a while to do. When adding a feed, you should also be able to add a name to that feed. That way the name of the feed could be assigned to every row in the big XML at the end.
    That value also needs to be output through Javascript.


  54. Bobby said: June 5, 2009 at 6:03 pm | Permalink

    Yeah, that sounds right. But I’m a js idiot — probably an idiot generally, but certainly when it comes to js. Sounds like a lot of work. Maybe something for the rainy day list. Thanks again for everything!


  55. Shrihari said: June 11, 2009 at 2:02 pm | Permalink

    Hey Gaya,

    Your demo just shows a black rectangle with “Loading tweets” text…


  56. Gaya said: June 11, 2009 at 4:42 pm | Permalink

    Thanks Shrihari! Seems that I was running the old class. Fixed! Thanks for the heads up.


  57. Richard Tomsett said: July 11, 2009 at 7:47 pm | Permalink

    Like it! Found a small bug: I had tweeted something containing an ampersand, and AjaxTweets cut off the rest of the tweet after this ampersand sign. I’ve hacked a fix in the AjaxTwits.php file: Line 86 is changed from

    $insert->addChild(“description”, $this->items[$i]['description']);

    to

    $insert->addChild(“description”, htmlentities($this->items[$i]['description']));

    This fixes the problem, possibly a better/more robust way of doing this though, not sure? Bit of a n00b with processing feed stuff!


  58. Patrick said: August 19, 2009 at 10:16 am | Permalink

    hey. nice work but i got only the Loading Tweets screen like Freek do.

    http://www.jb69.de/twitter/

    chmod on cache-dir is 777.
    thanks for your help in advance.

    patrick


  59. Gaya said: August 19, 2009 at 10:57 am | Permalink

    Hey Patrick, seems like you forgot to enter “/twitter/” in the cache path. I think this will solve the problem :)
    Good luck!


  60. Patrick said: August 19, 2009 at 11:28 am | Permalink

    thats it. thanks a lot :)))!!


  61. Alex Burr said: August 20, 2009 at 2:22 pm | Permalink

    So here’s a weird one: Seems I’m getting a feed all right… but it’s certainly not *mine*…

    http://www.alexburr.com


  62. gagan said: August 22, 2009 at 6:54 am | Permalink

    I want latest updated tweets code without using any username and password if you have code like this then email me.

    $ajaxTwits->addTimeline(“gayadesign”);
    $ajaxTwits->addReplies(“gayadesign”);

    I don’t want to use username and password…


  63. Gaya said: August 22, 2009 at 11:22 am | Permalink

    @gagan you only need to use a username, no password required. So I don’t quiet understand what you are saying.


  64. Gilberto said: August 25, 2009 at 7:05 pm | Permalink

    Thanks for this great script. I have just now incorporated it into my website and I am truly impressed with the results. Thanks for the effort you put forth on this. Gilberto at http://www.sampasystems.com/


  65. Yoosuf said: August 26, 2009 at 12:30 am | Permalink

    Perfect solution in the perfect time!

    Thanks for DMing me this, and its so useful, hope you will share the LastFM’s class :)


  66. Alex Burr said: August 26, 2009 at 9:38 pm | Permalink

    Any idea why other people’s Tweets are showing up?


  67. Gaya said: August 27, 2009 at 8:09 am | Permalink

    @Gilberto:
    Cool! Glad you liked it!

    @Yoosuf:
    No problem buddy. I don’t have an last.fm class, but this post explains how it works:
    http://www.gayadesign.com/diy/reading-xml-with-php/

    @Alex:
    Maybe because you are reading replies? Replies to you will be shown.


  68. Alex Burr said: August 27, 2009 at 3:13 pm | Permalink

    Yeah most of what’s showing up are tweets from people I’ve never even heard of let alone replied to… and they’re usually in Japanese. No idea what’s going on.


  69. Alex Burr said: September 1, 2009 at 2:53 pm | Permalink

    Well I figured it out. I was leaving the argument for addReplies() blank and was therefore receiving random replies to everyone, not just my account.

    I tried commenting out the line $ajaxTwits->addReplies() but that just breaks everything. Is there a way to get only my posts and not those that are a response from someone else? I don’t really care to feed other peoples’ tweets to my website.


  70. Gaya said: September 1, 2009 at 3:36 pm | Permalink

    Weird… the script should be working without using addReplies. I’ll check it out.


  71. Gilberto said: September 3, 2009 at 1:25 pm | Permalink

    This script was working perfectly and suddenly stopped working. I made the change to the new code but still does not work. I get a “PHP Fatal error” in the error log. Has anybody experienced this? I love this script when it is working!


  72. Gaya said: September 9, 2009 at 10:40 am | Permalink

    @Gilberto:
    Are you using PHP 5.2.0 or higher and have SimpleXML?


  73. Gilberto said: September 17, 2009 at 3:25 pm | Permalink

    Hello Gaya… Thanks for the note. Yes, I was using the program without any problem and it simply stopped working. I am using VodaHost and they use all of the most up to date software. I am sure that they are using the latest version of PHP but I don’t know about SimpleXML…


  74. Gilberto said: September 17, 2009 at 3:30 pm | Permalink

    Hello again Gaya… Sorry – VodaHost uses PHP 5.2.9 if this might be be the problem…


  75. TC said: October 2, 2009 at 1:21 am | Permalink

    Nice Twitter script! Your tweets look awesome on my page. Now, I’d like to display my own tweets, but when I replace “gayadesign” with “Solanablogger” in both AjaxTwitsRequest and AjaxTwitsUpdate, I get no feed at all, just “loading tweets…”

    Any thoughts/ ideas? Solanablogger is my correct Twitter username, so I’m not sure what to try next. My hosting co. says they support PHP with JSON and SimpleXML.

    Here’s the page (with your tweets): http://www.sbscuttlebutt.com/test_tweets.html


  76. TC said: October 2, 2009 at 9:53 pm | Permalink

    Addl info: using PHP 5.2.9
    PHP with JSON and SimpleXML

    When I replace gayadesign username with Solanablogger, I get this:

    PHP Fatal error: Call to a member function attributes() on a non-object line 132

    Also, when using gayadesign in AjaxTwitsRequest.php file, cache folder contains ajaxtwits.xml plus gayadesign.xml.
    However, when both are deleted and username Solanablogger is used in the AjaxTwitsRequest.php file, a file named Solanablogger.xml is created, but no associated ajaxtwits.xml file is created. Not sure why this is.


  77. Z said: November 20, 2009 at 2:35 am | Permalink

    Huh,

    I have the same problem as few people here.

    I dont jave response text from php.

    So Ive looked into it and the problem is not in php, its in ajax.

    I simply put only echo ‘test’; inside of AjaxTwitsRequest.php, and logically the JavaScript should return only that, but nothing happens.

    Than I put alert(xhr.responseText) into ajax like this:

    if(xhr.status == 200) {
    eventhandler(xhr);
    alert(xhr.responseText);
    }

    just to see if it fetches anything, but I get empty string.

    So whats the problem than?

    Any idea?

    Btw, Im using local server (XAMPP), but that should not be a problem right?


  78. Z said: November 20, 2009 at 4:09 am | Permalink

    About my post an hour ago… forget it, lol!

    It was my fault about the ajax… ups :)

    But there was a problem with getting response from php… and the problem was I didn’t specified the path to “cache” well… I haven’t read your instruction, but went by logic and just put the path from the folder that .php files were in…

    Now all works fine except “cacheTime”

    Ive put 1, but it doesnt work. Old .xml files are still in the cache.

    Why is that?


  79. Z said: November 20, 2009 at 4:10 am | Permalink

    lol, now I see I havent posted anything about an hour ago! lol xD


  80. duane said: December 2, 2009 at 11:29 pm | Permalink

    Is there any fix for when the tweets have long web urls? it seems to go out of the area and doesn’t break or line wrap the url.

    thanks.


  81. Gaya said: December 3, 2009 at 9:21 am | Permalink

    @duane: you can give the container of the tweets a width and add “overflow: hidden” in the CSS


  82. duane said: December 15, 2009 at 6:53 am | Permalink

    thanks Gaya. Seems to do the trick.


  83. Richard said: January 17, 2010 at 8:16 pm | Permalink

    Great script!

    One problem, though. It’s not refreshing the XML at the specified interval. If I delete it from cache, it pulls a new one; but it’s not automatically updating.

    I did make two changes, but I don’t think these would cause the problem:

    1. Commented out the replies feed in AjaxTwitsUpdate.php . I don’t want the replies posted in the feed.

    2. Added target attribute in AjaxTwits.js ~ line 66, thus:

    var a = document.createElement(“A”);
    a.href = ans.item[i].url;
    a.className = “twitter-link”;
    a.target = “_blank”;
    a.innerHTML = “# posted ” + ans.item[i].date;

    Any ideas?

    Cache time is set to 15 in AjaxTwits.php , AjaxTwitsRequest.php , and AjaxTwitsUpdate.php .

    Thanks,

    Richard


  84. Gaya said: January 18, 2010 at 9:10 am | Permalink

    @Richard:
    Have you set the correct path to the caching dir and made it chmod 0777? That is the problem most of the time.


  85. Umar said: February 4, 2010 at 4:10 am | Permalink

    Hi Gaya, thanks a lot for the script. Took me ages to realise why my tweets weren’t showing up, and it turns out one of my urls in the tweet was causing the problem, do you know a way around it?

    This is part of the php error:

    “SimpleXMLElement::addChild() [simplexmlelement.addchild]: unterminated entity reference blog=1″

    Thanks


  86. ka-chiiing said: February 22, 2010 at 12:38 pm | Permalink

    hi there,

    thanks for this nice script, it’s working great!

    one question though, just to understand the concept and to check if it’s working right … the xml file in the cache folder will automaticallly be written on every first request to that page and then be cached. it won’t create a new .xml file without request, right?

    thanks, j


  87. ka-chiiing said: February 22, 2010 at 3:49 pm | Permalink

    in order to fetch the results for a search, what would i need to enter? i tried several options:
    http://search.twitter.com/search?q=surfing
    #surfing
    search?q=surfing
    etc.
    thanks, j


  88. Gravity said: March 5, 2010 at 5:20 am | Permalink

    Well the demo looks good, but I can’t seem to get it working at all on my site. I believe the AjaxTwitsRequests & Updates.php files work fine, since the /cache folder is filling up. However, it’s just showing absolutely nothing under the Loading Tweets notice.

    Got any ideas?


  89. bobby said: March 27, 2010 at 6:32 pm | Permalink

    I just tried downloading the script to use in a second site (having used this effectively on a first site). It appears that the `AjaxTwitsUpdate.php` and `AjaxTwitsRequest.php` files in the zip folder are identical. That must be a mistake, right?


  90. Flapane said: April 6, 2010 at 5:29 pm | Permalink

    please can you tell me how to disable the avatar in your beautiful script? Thanks!


  91. Flapane said: April 6, 2010 at 6:09 pm | Permalink

    Oh, I forgot to ask how to use the european date format dd-mm-yy.
    Thanks!


  92. Flapane said: April 6, 2010 at 6:19 pm | Permalink

    Weird…
    all of a sudden it stopped working:
    Log says
    [06-Apr-2010 19:10:31] PHP Fatal error: Call to a member function attributes() on a non-object in /home/flapanec/public_html/twitter-homepage/AjaxTwits/AjaxTwits.php on line 130
    [06-Apr-2010 19:13:54] PHP Fatal error: Call to a member function attributes() on a non-object in /home/flapanec/public_html/twitter-homepage/AjaxTwits/AjaxTwits.php on line 130


  93. Flapane said: April 6, 2010 at 6:29 pm | Permalink

    I left you a testpage… http://www.flapane.com/test.php


  94. Chandra said: April 24, 2010 at 1:04 pm | Permalink

    Auto update is not working. i has refresh but still not update my new tweet


  95. jason said: May 1, 2010 at 8:28 am | Permalink

    I’m also having problems with the script. I started working with it within a drupal mod and it wasn’t working, so I tried the simplest possible implementation with it at the root of a new empty “site” with a single page.
    I’ve tried a ton of different paths for includes, and even making every uri absolute as a last resort.

    It’s a great idea in it’s relative simplicity – I’d love to get the implementation as a Drupal module going.

    I’m running php 5.2.11 with json 1.2.1 and SimpleXML revision 272374 on MAMP.

    @Gaya:
    Thanks for all the work you have put into this to date.

    -jason


  96. Eric said: May 25, 2010 at 10:01 pm | Permalink

    Trying to get this to work, everything works fine in Chrome and FF but in IE I get Unexpected call to method or property access in the scripting due to the lines

    twitter.removeChild(twitterload);
    and then
    twitter.appendChild(li);


  97. Joao said: August 28, 2010 at 5:45 pm | Permalink

    Hey gaya!

    I’m trying to feed 1 tweet only, but when i change the values “item Count = 1;” nothing appears on the page besides a sudden flash of “Loading Tweets”.

    Can you help me out?

    Thanks


Leave a Comment

Your email is never shared. Get your own avatar with gravatar! Required fields are marked *

*

*



5 Trackbacks

  1. By Tweets auf der eigenen Website einbetten on March 29, 2009 at 10:37 am
  2. By Twitted by paviles on May 12, 2009 at 12:23 am
  3. By ToDo on June 3, 2010 at 12:18 pm