Skip to content

Instantly share code, notes, and snippets.

@keiya
Created September 15, 2011 14:08
Show Gist options
  • Save keiya/1219324 to your computer and use it in GitHub Desktop.
Save keiya/1219324 to your computer and use it in GitHub Desktop.
bit.ly shortener function in Lua
function bitlyshorten(longurl)
local http = require('socket.http')
--please specify your account ID and API key
local r,c = http.request('http://api.bitly.com/shorten?login=YOUR_LOGINID&apiKey=YOUR_API_KEY&longUrl='..longurl)
local json = require('json')
local decjson = json.decode(r)
local shorturl
for k,v in pairs(decjson.results) do
shorturl = decjson.results[k].shortUrl
end
return shorturl
end
--local shorturi = bitlyshorten('http://www.example.com/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment