Created
September 15, 2011 14:08
-
-
Save keiya/1219324 to your computer and use it in GitHub Desktop.
bit.ly shortener function in Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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