Converting long URLs to short bit.ly URLs in #rstats

272 views
Skip to first unread message

Scott Chamberlain

unread,
Feb 12, 2012, 9:30:00 AM2/12/12
to ropensci...@googlegroups.com

So, sometimes resources pulled down in our pkgs have very long URLs, so it would be nice to shorten these to provide tidy data outputs for users. 

I know you can convert long URLs with the bit.ly API within #rstats, but is there an internal method within R that could make the conversion faster?  Or, maybe there is a way to speed up conversions beyond the default bit.ly API functionality?

Scott

Carl Boettiger

unread,
Feb 12, 2012, 12:41:59 PM2/12/12
to ropensci...@googlegroups.com
Is bit.ly API already implemented in  R?  That would be kinda cool.  Is it authenticating each time?

If I recall, bit.ly API has somewhat severe rate limiting.  I've been making system() calls to command line script which uses either google or tinyurl, seems to work okay; but I've never tried producing 1000s of urls in a single function call. 

Carl
--
Carl Boettiger
UC Davis
http://www.carlboettiger.info/

Scott Chamberlain

unread,
Feb 12, 2012, 1:32:39 PM2/12/12
to ropensci...@googlegroups.com
I don't know if bitly authenticates each time - could you just authenticate once in a session using RCurl somehow, then make many calls?  At first the docs said you can only put one URL to shorten in each call, but then there is a method to do 15 at once somehow ("The bitly API does not support shortening more than one long URL with a single API call. However, up to 15 URLs can be handled in one API call using the “/v3/lookup,” “/v3/expand” and “/v3/clicks” endpoints."). Hmmm...

Discussion in their google group suggests they aren't willing to reveal what their actual rate limits are, though they have them per minute, hour, day, etc.  Weird. So you just keep sending API calls until you get bounced I guess. 

There are actually a lot of different methods in the bitly API, see here, so it might be worth a whole package. 

I haven't tried tinyurl in R yet. 

Scott
Reply all
Reply to author
Forward
0 new messages