Hey there, I saw this being used on a Drupal site run by someone I know and it sorta annoyed me that this thing was just dropping an iframe in to the tweetmeme website which then shows a link with href="JavaScript: popup();", which is obviously far from ideal

so, considering they expose their API in a multitude of formats, we should only grab the data from them and do the rest ourselves

I'm not entirely sure if it's feasible to use their PHP API on the server-side, as this will probably require some sort of caching, but it allows us to do better error handling.

attached patch is just a quick hack as an example on how it could be handled, in an ideal implementation, I think we should offer the user a choice as to the method of grabbing it and as to the caching

If there is interest in this approach, I'm willing to work out a more solid implementation.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RobLoach’s picture

Title: avoid using an iframe and rely less on javascript » Use TweetMeme API instead of JavaScript

Hmm, I like it a lot! Could we potentially provide this as an option? If in some cases, the website caches heavily, this value wouldn't be updated frequently and the value would become old due to the page cache. Having an option would allow the user to choose the best option for their site.

seutje’s picture

sure, I'll look into that when I find some spare time (prolly not gonna be any time soon q.q)

also, in the example I posted I used the serialized php API, which turns out to be pretty much the most unsecure way of doing it

fortunately, they also provide a JSON API, which is pretty secure :D

pribeh’s picture

Any update on this. I'd love to be able to customize the display of the data.

seutje’s picture

FileSize
5.84 KB

ok, I finally found a minute to work some on this
attached patch adds a select to the settings, labeled "API" with the options "iFrame" and "JSON"
if JSON is chosen, the theming function calls tweetmeme_get_json and constructs the elements using the data returned, if this call fails, it'll fall back to the iFrame
I'm not sure if tweetmeme_get_json is a good name for the function, as it doesn't rly return JSON, but a php object
I'm also not too sure if this is the best way to go about it, it always feels nasty to go grab data from within a theming function, perhaps we should split it up and go sorta like this:

if API == iFrame -> call theme('tweetmeme_iframe', url, style), done
if API == JSON -> call tweetmeme_get_data(url, json), if that fails, call theme('tweetmeme_iframe', url, style), if it succeeds, call theme('tweetmeme_button', data, url, style), done

also, u'll notice that I did some weird stuff to grab the ID separately coz for some reason they don't return it as a separate value in the object. This is mainly for the next step I was thinking about, which is sort of a mechanism to have up-to-date numbers while having cached pages.
I was thinking of making a behavior that updates the number once everything else on the page is done loading and perhaps optionally have an interval to keep updating it without a pageload
but that's not for right now, I'd rather polish the more static-y method first

I tried to keep the CSS to a minimum while retaining the distinct TweetMeme look (actually used less CSS than they do in their lil iframe, which makes no sense, but w/e)
both normal style and compact only tested in garland
(I linked the background-image to the one on their server as it's prolly not GPL and I don't think I can just recreate it without violating something)

oh, and patch is against HEAD, which seems to be missing some features in comparison to the latest stable...

seutje’s picture

FileSize
5.78 KB

hehe upsy, forgot to remove my test-url :x

jayson’s picture

Hi, just wanted to mention that this patch fails to apply to 6.x-1.3 and also fails to apply to 6.x-1.x-dev. Does anyone know if there is a solution in the works planned to be integrated into this module?

locomo’s picture

subscribe

netsensei’s picture

subscribing.

Twitter now has it's own Tweet button which also just drops an iFrame on your site. I'm not to keen of this approach myself. I can see the rationele behind it though: provide a fast, platform-independent way to integrate the button on your site.

Maybe we should expand the module and also integrate the Twitter button itself too? Or would that be feature overkill given that the module currently focusses on TweetMeme?

RobLoach’s picture

I'd love to get the support in for this. If the patch is updated, and gets to RTBC, I'd have no problems committing it.

Maybe we should expand the module and also integrate the Twitter button itself too? Or would that be feature overkill given that the module currently focusses on TweetMeme?

http://drupal.org/project/tweetbutton :-)

seutje’s picture

yea, I'm probably not going to be able to do this any time soon, but I'll get on it when I find some spare time