Kilometer0

Twitter Status URL’s and Ampersands « Km0 Blog

Twitter Status URL’s and Ampersands
- by Alexandru Petrescu

Recently I’ve had to do a bit of integration with Twitter on a site I was working on.  In order to allow people to easily post links to Twitter, I created specially formed URL’s to pass a message and link to Twitter.

Making the URL is simple, it looks something like this:

http://www.twitter.com/home?status=Your+Message+http://mylink.com

However, if you add an Ampersand (&) to the message it breaks the URL, like so:

http://www.twitter.com/home?status=Your+Message+&+something+http://mylink.com

You can escape the ampersand using %26, however it shows up as %26 in the actual message, like so:

http://www.twitter.com/home?status=Your+Message+%26+something+http://mylink.com

It seems that Twitter doesn’t want to use www.twitter.com as their main domain.  They want to use twitter.com, so they redirect.  When they redirect, it does encodes the previous url and passes it to the twitter.com domain.  So %26 turns into %2526 (%25 = %).

However, if you form your url to go directly to http://twitter.com it won’t do the redirect and it’ll work just fine.  So the final good url is:

http://twitter.com/home?status=Your+Message+%26+something+http://mylink.com

Last tip, if you use this method of posting to Twitter, make sure you send the user to http://twitter.com/home?status=your+message and not to http://twitter.com/?status=your+message.  The http://twitter.com URL works if you’re already logged in (which you might be if you’re developing the application), but if you have to login first, it won’t forward the message.  Going to the /home page will allow you login and then forward the message.

Also, when making the url’s make sure you use +’s and not %20′s.

share
 

Leave a comment

You must be connected to post a comment.