Tweet This with Symphony and bit.ly
This is an open discussion with 1 reply, filed under General.
Search
Great idea. I'll have to finish my Twitter extension soon. These to methods would work well together.
Create an account or sign in to comment.
I tweeted this weekend about creating a "Tweet This" button using Symphony and the bit.ly API, and Anders suggested I post the solution here.
It's fairly straightforward. The first thing to know is the URL for posting to Twitter:
When a user follows that link, whatever argument is passed to the
status
parameter will be pre-loaded into her/his status field (assuming they're logged in to Twitter). The most common use of this is, of course, to pass a URL.The difficulty then is to keep the URLs as short as possible because of Twitter's 140-character limit. What we want, on the Symphony end, is to auto-generate shortened URLs for any entries/pages on which our "Tweet This" button will appear. Luckily, URL-shortening service bit.ly has a pretty simple XML API, and Symphony makes pulling in external XML a breeze.
Step One: Get a bit.ly API Account
Register for bit.ly. Once you've registered, log in and go to your account page. You'll see your API login and API Key in the left sidebar. Copy them.
Step Two: Create the Short URL Datasource
Create a new datasource (mine is called Short URL) with
source
set to Dynamic XML, and the following URL (replace the two all-caps strings in square brackets with your API Login and API Key):Step Three: Attach the Datasource
Attach the datasource to any page(s) on which you want to have a "Tweet This" button. Because it uses the
{$current-url}
param, it doesn't matter if your page is static or accepts lots of parameters for displaying entries. You'll get a unique shortened URL for every possible URL on that page.Step Four: Build Your Link
In your XSL templates, build the Tweet This link:
Of course, you can always add some other elements since the URLs themselves are shortened:
I wrap mine in an
xsl:if
too, just to be safe. If I've forgotten to attach the DS or the bit.ly API isn't available, the link won't display:That's all. Like I said, fairly straightforward but hopefully someone will find it useful. And feel free to suggest improvements here...