Decided to play around with the instagram api. This is a simple app that loads 24 most popular thumbnails. Tap the screen to update. Ugly code but I found it to be fun. It also loads slow.
http://www.youtube.com/watch?v=C0Lv4QkuZo0
This requires the json library If you do not have it here it is: https://dl.dropboxusercontent.com/s/9e4nvqeu4hsux2q/Json.lua?token_hash=AAFyMB98j4bnt_1gawf9wSke52hsoC7hsIvARcTuZNeOEw&dl=1
Either save it as a tab or link it. I’d recommend having a JSON Library project because if you do any API work you’ll need it.
-- Instagram
-- Use this function to perform your initial setup
displayMode(FULLSCREEN)
function setup()
instagram = {}
images = {}
colCount = 1
x = 90
y=HEIGHT-80
finished = false
getPopular()
getPopular()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50,255)
displayImages()
end
function touched(touch)
if touch.state == ENDED then y = HEIGHT - 80 getPopular() getPopular()end
end
function getPopular()
finished = false
images = {}
local clientid = "2101a06164e04b60b1ace551b8d1a6a8"
local url = "https://api.instagram.com/v1/media/popular?client_id="..clientid
http.request(url,function(d)
print("Entered callback")
instagram = json.decode(d)
loadImages()
end,function(d) print(d) end)
end
function loadImages()
for i=1,#instagram.data do
if instagram.data[i].type == "image" then
local url = instagram.data[i].images.thumbnail.url
http.request(url,function(d)
local tmp = {user = instagram.data[i].user.full_name,id=d}
table.insert(images,tmp)
end)
end
end
finished = true
end
function displayImages()
local width = math.floor(WIDTH/160)
for i=1,#images do
if i > 24 then
--do nothing
else
sprite(images[i].id,x,y)
fontSize(14)
text(images[i].user,x,y-85)
end
x=x+160
colCount = colCount + 1
if colCount > 6 then y=y-170 colCount= 1 x = 90 end
end
colCount = 1
y=HEIGHT-80
x=90
end