-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.rb
More file actions
37 lines (29 loc) · 926 Bytes
/
app.rb
File metadata and controls
37 lines (29 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
enable :sessions
CALLBACK_URL = "http://instagram.dev/oauth/callback"
Instagram.configure do |config|
config.client_id = CLIENT_ID
config.client_secret = CLIENT_SECRET
end
get "/" do
'<a href="/oauth/connect">Connect with Instagram</a>'
end
get "/oauth/connect" do
redirect Instagram.authorize_url(:redirect_uri => CALLBACK_URL, :scope => 'comments relationships likes')
end
get "/oauth/callback" do
response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL)
session[:access_token] = response.access_token
redirect "/feed"
end
get "/feed" do
client = Instagram.client(:access_token => session[:access_token])
user = client.user
html = "<h1>#{user.username}'s recent photos</h1>"
for media_item in client.user_recent_media
html << "<img src='#{media_item.images.thumbnail.url}'>"
end
html
end
get "/access_token" do
'access_token: ' + session[:access_token]
end