Search code examples
javascripttwitterurl-shortener

Automatic url shortening with a custom Twitter tweet button


Is there a way to make twitter generate a shortened version of my url when using a custom button (according to: https://dev.twitter.com/docs/tweet-button#build-your-own).

I don't need any counters, I just want to share a text, shortened url and a hashtag.

var twUrl = 'http://twitter.com/share?count=none&text=' + encodeURIComponent(text) + '&url=' + url + '&hashtags=' + encodeURIComponent(hashtags);
    window.open(twUrl, 'sharer', 'toolbar=0,status=0,width=650,height=254');

Thanks!


Solution

  • You can use the bitly API to shorten your url's.

    Checkout the documentation: http://dev.bitly.com/get_started.html

    See also this SO question with a code example in the answer on how to make use of the bitly API using jquery: jQuery on the fly URL shortener