MooTools TwitterGitter Plugin

Everyone loves Twitter. Everyone loves MooTools. That's why everyone should love TwitterGitter, a MooTools plugin that retrieves a user's recent tweets and allows the user to format them however the user would like. TwitterGitter allows the user to choose the number of tweets to retrieve and returns an object containing the data provided by Twitter.

I love almost every part of being a tech blogger: learning, preaching, bantering, researching. The one part about blogging that I absolutely loathe: dealing with SPAM comments. For the past two years, my blog has registered 8,000+ SPAM comments per day. PER DAY. Bloating my database...

My trip to Mozilla Summit 2013 was incredible. I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out. MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...

Everybody and their aerobics instructor wants to be able to edit their own website these days. And why wouldn't they? I mean, they have a $500 budget, no HTML/CSS experience, and extraordinary expectations. Enough ranting though. Having a website that allows for...

Discussion

While I like this little class the obvious problem is that you don’t cache the results on your server making a request to twitter on every pageload by any user. This probably gets your domain blocked fast if you have a high volume website.

So everytime the git link is clicked, a new instance of TiwtterGetter is created? Even if you abstract that portion out, and just call myTwitterGitter. retrieve() on every click, a new instance of jsonp is created.

You should probably write a second class to handle the links’ interaction with the twittergetter class, it would be very small, but it would separate some of the concerns.

@EmEhRKay: I understand your concern, but when putting this together, my thought was how bloggers could use this to pull their updates into their blog — NOT using this for a ton of users. I meant to keep this simple.

@David – I understand that, and I love your blog for it (stalking remember? lol), and I love the fact that you come up with so many cool concepts and techniques. The thing that gets me is that I feel sometimes the examples do not necessarily program to the pattern.

It would be very easy for you to create and reuse a single instance of the class — you’re pretty much a MooTools front man, your code is go beyond “oh this is cool” and add “this is the correct way its done.” With your example, I see no need to create the TwitterGitter class if a new one is created everytime an update is requested from the Twitter server, it could just be a function if it is giong to act in that manor. If I remember correctly, there is a way to bind a class instance with an event allowing for great reuse, but maybe you can write about that some more in the future.

Nice Job. The caching issue, as it has already been pointed out is a non issue. The only thing that twitter requests to play friendly is to send since_id. How the class currently works I don’t see this as an issue. If the class was modified to auto refresh tweets ( a periodical ). It would be necessary to update the oncomplete to update the since_id.

You don’t understand my concerns. The Referrer is most probably sent with the request or at least it is possible for twitter to identify the domain from which the calls come from. If you, for example, integrate this script into the sidebar of digg (=a high volume website) and show the five latest messages of a user on every page request by every user of digg you’d certainly get banned by the twitter api as you make to many requests to the twitter api. That is why you always should cache such things on your server and request it from there. Another thing is when the service wents down (= quite usual with twitter), you’d still have a cached version to show.

See: “I keep hitting the rate limit. How do I get more requests per hour?” on Twitter APIs

@Chis: Maybe you’re right. It looks like they might limit requests per Twitter account, too. I thought it was only by IP address. They could also check the referrer, but I doubt they would since it can be easily spoofed. AFAIK, there is no fool proof way to tell where the request came from other than by client IP address.

Either way, I think if you have high enough volume for it to matter, you should probably be doing this on the server side anyway. Caching is easy in that case. Caching doesn’t make sense at all for this plugin.

So why no just use hash cookie to write the last 5 messages you receive to a cookie as an object and date stamp it? I know cookies are ‘precious’ and should not be abused, but this is 5 x 140 char so that seems pretty sensible to me…

Elkalidi Abdelkader

Thanks for sharing David, but I think the Cross-Domain is not a good idea, especially when we tried to call a page that we do not control, XSS will be a cochmar.

Alelo

the simple way is to make a php script with a 2? field table 1. Timestamp 2. twitter request
class -> ajax -> php script
1. if yet dif to timestamp is > 5mins? new request and insert request+ timestamp into table
2. if yet dif to timestamp is < 5mins? request is taken of table

@Daniel Buchner: You could certainly cache with cookies, but there’s not much benefit. The only way it would help is if a user were to reload the page within the caching time window. It wouldn’t save many requests to twitter.com overall. I.e. there is no way for multiple users to share the cache.

You could cache like @Alelo suggests on the server side, but if you do that, why would you even bother using this plugin?

Love all your work. Thanks for sharing and giving so much to the MooTools community. I’ve been gleaning a lot lately. I thought I’d let you know, I made this little site the other day based on your plugin:http://simpletweet.com/

It’s pretty straightforward, but it works for what I wanted it to do. I was previously doing it with a totally different method, but “TwitterGitter” does the job! So thanks!

I would definitely recommend keeping a cache there is no reason not to; although, you wouldn’t want to use a cookie as it is pointless.

So with a proper cache, you update most frequently at 1min making 60 calls to twitter in 1 hour. (There is no reason to hit if more often as it is cached by twitter anyways)

Using the method without cache you could be hitting the Twitter server for thousands of hits per minute depending on the site’s traffic.

Be considerate of Twitter’s servers.

h-a-r-v

How about doing it this way? http://www.widgetbox.com/widget/twidget – looks very reasonable – simple and functional. Slidewhow of all messages – unlimited, takes very little space and you can set it to show particular twitter by default. Would be great to see a mootools version.. As we all know, flash sucks.

Just a little gotcha: The regex behind the ‘linkify’ method will cause problems if the link is contained within parentheses or brackets (the end bracket will become part of the link). If you want to fix this, replace the \S in the first group with [\w\-:;?&=+.%#\/]

Hey David,
Just wanted to let you know that TwitterGitter conflicts with the Mootools Swiff class. Not that it matters, I just wanted to save anybody who actually wanted to use the two together (like I tried doing) the headache of what the problem might be. If I come up with a solution I’ll email it or post it.

@David I’m not exactly sure right now, I’m still messing around with it, but TwitterGitter simply doesn’t work, and if I execute it in the DOMready event before the swiff object then the SWF simply doesn’t inject into the document. If I implement it after then it still doesn’t work, but at least the swf is injected into the document. I’m still working on it. I’ll let you know.

i saw twittergitter on another website (http://www.epitonic.com/) and really like it, but really am an amateur website builder. i need an installation package for dummies i guess -that shows exactly what i need to put in the head, all the files to upload and what to put in the body, all in the context they actually go in.

if this is possible, i would very much appreciate it. i’ve tried following a few examples, but can’t figure out.

tnx, wanda.

kolin

not sure if this is an issue, or i’m getting the wrong json response, but the response doesn’t seem to include retweets, but includes them in the count.

for example if i have a count of 5, but there are 3 retweets in there, it only actually shows 2 tweets.

anyone know if this is by design? the .json also doesnt show retweets in there.

on comments there I thanks to both sources, I’m newie to MooTools so don’t be that rude with my code…

I’d like to hear opinions anyway

pSouper

Hi David et al,
I have a come up with a strange problem with twitterGitter – for one twitter account it is only getting tweets up until a date two months ago…

1: the tweets are not being cached in anyway
2: the tweets just seemed to stop at that date and not progressed since (for this account only)
3: ths account has plenty of tweets since this date
4: when i change the twitter account it shows them up until the latest tweet.
5: this problem persists using your demo code too.

Is it possible to that this account (a quite prolific tweeter) has so many tweets that the twitterGitter/twitterAPI has a limit of some kind that was met/exceeded at this date?
– such as get 64k tweets from tweet#1 and this happens to be the tweets at this date.

any help on this strange problem is very welcome.

twitter account concerned is available on request :)

thanks D,

2G

Hello,
Your class work done, on my website.
But I have got simply one question, How do you change format date on ccs or js ?

Continue this conversation via emailGet only replies to your comment, the best of the rest, as well as a daily recap of all comments on this post. No more than a few emails daily, which you can reply to/unsubscribe from directly from your inbox.