Shorten URL’s with Bitly using YQL

Bitly is a great URL shortener which also provides a very neat API. If you’re as API driven as me and love to automate the tasks around you, you’ll be happy to note that there is a new open data table that can shorten URL’s using YQL.

The API is neat but why remember the query parameters of a service when YQL can do the work for you?

use 'http://nagiworld.net/yqldefs/bit.ly.shorten.xml';
select * from bit.ly.shorten where login='nag...' and apiKey='....'
           and longUrl='http://cnn.com/'

This looks pretty easy but seems like a lot of work for a single URL to be shortened. Isn’t it? You can always go to the bit.ly site and do the same in a single click. right? Yes! Infact the reason for this table is to shorten multiple URLs in a single statement using a YQL sub-select i.e.

select * from bit.ly.shorten where login='nag...' and apiKey='...'
       and longUrl in ('http://cnn.com', 'http://yahoo.com')

The output of the query looks like the following. Only the results element is shown here for brevity. Given this data, I can project the necessary fields and get either the shortened url or other elements.

    <results>
        <bitly>
            <errorCode>0</errorCode>
            <errorMessage/>
            <results>
                <nodeKeyVal>
                    <userHash>xzV1m</userHash>
                    <shortKeywordUrl/>
                    <hash>31IqMl</hash>
                    <nodeKey><![CDATA[http://cnn.com/]]></nodeKey>
                    <shortUrl>http://bit.ly/xzV1m</shortUrl>
                </nodeKeyVal>
            </results>
            <statusCode>OK</statusCode>
        </bitly>
        <bitly>
            <errorCode>0</errorCode>
            <errorMessage/>
            <results>
                <nodeKeyVal>
                    <userHash>h4H0n</userHash>
                    <shortKeywordUrl/>
                    <hash>2deaFR</hash>
                    <nodeKey><![CDATA[http://yahoo.com]]></nodeKey>
                    <shortUrl>http://bit.ly/h4H0n</shortUrl>
                </nodeKeyVal>
            </results>
            <statusCode>OK</statusCode>
        </bitly>
    </results>

Better yet, take an entire html page, rss/atom feed or even a CSV file as an input containing all the URL’s to be shortened and zip it through YQL in a single statement. Now, Insn’t that something cool!

select * from bit.ly.shorten where login = 'nag..' and apiKey='...'
    and longUrl in (select link from rss where url='.....')

Note: Once you register with bit.ly, you can find the apiKey by going to the Account section.

This table is already checked into the YQL Open Table github repository. There are many other open data tables of use ranging from bit.ly to amazon to iplocation contributed by the community.

Lastly, if you’d like to contribute your awesome open data table you can checkout Fork me! YQL Open Tables!. This article gives an excellent overview of how to get your table into github.

Share
  • del.icio.us
  • Facebook
  • Digg
  • description

No related posts.

  • http://www.ResumeBuilderPlus.com resume wizard

    I've seen a lot of tools like this one, but this really works well thanks a lot for sharing..

  • http://fashion4us.com hk fashion wholesale

    Thanks sharing such an informative discussion with us. I really like your suggestion.

  • http://www.sunglassesuk.com/Diesel_Sunglasses.asp Diesel Sunglasses

    Good stuff.

  • http://www.ResumeBuilderPlus.com resume building

    there's a lot of work to be done by using that one, I rather go with tinyurl.com, with just one click you will shorten your url…

  • max191

    I entered your blog from google search. You really have done a good effort. Thanks for the wonderful blog.
    regards
    charcoal grill

  • neeson02

    This information helped me a lot. I was looking this information for a long time. Thanks for sharing.

  • Davian

    That is a great Idea..and some useful code. Thanks for Posting..

  • http://hareton.myopenid.com/ Hareton

    thanks a lot. I have never thought tha it could be so easy and so useful at the same time! eager to learn more about YQI I found this useful guide http://www.pdfok.com/watch/yql-set.pdf-8129984…. Hope to become a real profi soon:)

  • RainSanders

    You've guessed. I'm really happy about it. It makes the thing much more easier and convenient. I've found a video which describes it: http://www.videorolls.com/watch/How-to-use-bitl... I'm sure that after this post and the video nobody will have any problems.

  • http://pdfdownloadebook.com pdfdownload ebook

    Better yet, take an entire html page, rss/atom feed or even a CSV file as an input containing all the URL’s to be shortened and zip it through YQL in a single statement. Now, Insn’t that something cool!

blog comments powered by Disqus