Been working on a new project that will go into previews for selected friends and family later this week and go into general release a few days later, once I've had a chance to fix any issues my preview users find.

One part of the project was to add "Tweet This" links to certain items on the site, where clicking on the link would send the user to Twitter and fill in the suggested text of the tweet for them.

It's actually a lot simpler than you think. The format is: http://twitter.com/?status=[URL encoded tweet text].

Now many of you are asking how you "URL encode" the tweet text. Well, if you're using PHP, you use urlencode('text'); where "text" is the text of your tweet. If you want to do it in JavaScript, the PHP.js library has a javascript equivalent for PHP's urlencode.

But here's a little trick I didn't know about until I made this mistake. Make sure your link goes to twitter.com, not www.twitter.com. If it goes to www.twitter.com, the text doesn't get properly decoded. So, trying to tweet Creating a "Tweet This" Link - http://www.brainhandles.com would look like Creating a %22Tweet This%22 link - http%3A%2F%2Fwww.brainhandles.com, and nobody wants that.

  • Share/Bookmark
5 Responses to “Creating a "Tweet This" Link”
  1. Brian says:

    Great find on omitting www from the Twitter link. You saved me a few more hours of frustration!

  2. al says:

    What happens if the person who clicks the link is not logged into twitter before clicking?

  3. Nic says:

    It seems like not all characters need to be encoded. I think I got away with leaving spaces, slashes & colons. Does this sound like it would present an issue?

  4. Patis says:

    I'll second that thank-you for the tip about the link.
    Only thing that would be nice is if you mentioned how to integrate bit.ly (or something similar) into the link.

    Thanks for an awesome straight-to-the-point tutorial!

  5.  
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Get an angel for your site An Angel Watches Over This Site