Connect to Bit.ly API with MooTools


/ Published in: JavaScript
Save to your folder(s)

A simple way to send an ajax request to the Bit.ly API and return the shortened url.


Copy this code and paste it in your HTML
  1. /**
  2.  * author : Stephane P. Pericat
  3.  * date : 2010-03-02
  4.  */
  5.  
  6. var link = "http://www.snipplr.com/";
  7. var slink = null;
  8.  
  9. var short = new Request.JSONP({
  10. url: 'http://api.bit.ly/shorten',
  11. callbackKey: 'callback',
  12.  
  13. onSuccess: function (result) {
  14. slink = result['results'][''+link+'']['shortUrl'];
  15. console.log(slink)
  16. },
  17. data: {
  18. version: '2.0.1',
  19. longUrl: link,
  20. login: 'username',
  21. apiKey: 'R_dd761983d39ab216af226a19756496d3',
  22. format: 'json'
  23. }
  24. }).send();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.