User:Opensource Obscure/LSL/Bitly

From Second Life Wiki
< User:Opensource Obscure‎ | LSL
Revision as of 10:48, 30 May 2011 by Opensource Obscure (talk | contribs) (Working LSL snippet which uses llHTTPRequest to call Bit.ly APIs and shorten a link)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<lsl>

string LONGURL = "http://example.org";

string BITLY_USERNAME = "CHANGE_ME"; // SET THIS WITH YOUR DETAILS string BITLY_APIKEY = "CHANGE_ME"; // SET THIS WITH YOUR DETAILS // See bit.ly API docs // http://code.google.com/p/bitly-api/wiki/ApiDocumentation

string BASEURL = "http://api.bitly.com/v3/shorten?format=txt&domain=j.mp&"; // Alternatively: JSON and XML format, bit.ly instead of j.mp domain

default {

   state_entry()
   {
       llSay(0, "Hello, Avatar!");
   }
   touch_start(integer total_number)
   {
       llHTTPRequest(BASEURL +
       "login=" +
       BITLY_USERNAME +
       "&apiKey=" +
       BITLY_APIKEY +
       "&longUrl=" +
       llEscapeURL(LONGURL),[],"");
   }
   
   http_response(key request, integer status, list metadata, string msg)
   {
       if(status!=200) 
       {
           llOwnerSay("Error");
           llOwnerSay(msg);            
           return;
       }
       llOwnerSay(msg);
   }    

} </lsl>