Skip to content

Commit

Permalink
Remove INSTAGRAM_ACCESS_TOKEN.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Jul 7, 2015
1 parent 6e77dcb commit 2130a1f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
REDIS_URL=redis://localhost:6379/3

GOOGLE_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
GOOGLE_API_KEY=

FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=

INSTAGRAM_CLIENT_ID=
INSTAGRAM_CLIENT_SECRET=

# Google Webmaster Tools and Google Analytics
GOOGLE_VERIFICATION_TOKEN=googleXXXXXXXXXXXXXXXX.html
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ GEM
kgio (2.9.3)
method_source (0.8.2)
minitest (5.7.0)
multi_json (1.11.1)
multi_json (1.11.2)
multi_xml (0.5.5)
powder (0.3.0)
thor (>= 0.11.5)
Expand Down
4 changes: 0 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
"INSTAGRAM_CLIENT_SECRET": {
"description": "(Optional) Your Instagram client secret.",
"required": false
},
"INSTAGRAM_ACCESS_TOKEN": {
"description": "(Optional) Your Instagram access token. If you use this then you don't have to supply client id and secret above.",
"required": false
}
}
}
25 changes: 3 additions & 22 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,12 @@ def httparty_error(r)
erb :facebook_feed
end

get "/instagram/auth" do
return "Already authed" if ENV["INSTAGRAM_ACCESS_TOKEN"]

if params[:code]
response = HTTParty.post("https://api.instagram.com/oauth/access_token", body: {
client_id: ENV["INSTAGRAM_CLIENT_ID"],
client_secret: ENV["INSTAGRAM_CLIENT_SECRET"],
grant_type: "authorization_code",
redirect_uri: request.base_url+request.path_info,
code: params[:code]
})
raise InstagramError.new(response) if !response.success?
headers "Content-Type" => "text/plain"
"heroku config:set INSTAGRAM_ACCESS_TOKEN=#{response.parsed_response["access_token"]}"
else
redirect "https://api.instagram.com/oauth/authorize/?client_id=#{ENV["INSTAGRAM_CLIENT_ID"]}&redirect_uri=#{request.url}&response_type=code"
end
end

get "/instagram" do
return "Insufficient parameters" if params[:q].empty?

if /instagram\.com\/p\/(?<post_id>[^\/\?#]+)/ =~ params[:q]
# https://instagram.com/p/4KaPsKSjni/
response = HTTParty.get("https://api.instagram.com/v1/media/shortcode/#{post_id}?access_token=#{ENV["INSTAGRAM_ACCESS_TOKEN"]}")
response = HTTParty.get("https://api.instagram.com/v1/media/shortcode/#{post_id}?client_id=#{ENV["INSTAGRAM_CLIENT_ID"]}&client_secret=#{ENV["INSTAGRAM_CLIENT_SECRET"]}")
return response.parsed_response["meta"]["error_message"] if !response.success?
user = response.parsed_response["data"]["user"]
elsif /instagram\.com\/(?<name>[^\/\?#]+)/ =~ params[:q]
Expand All @@ -160,7 +141,7 @@ def httparty_error(r)
end

if name
response = HTTParty.get("https://api.instagram.com/v1/users/search?q=#{name}&access_token=#{ENV["INSTAGRAM_ACCESS_TOKEN"]}")
response = HTTParty.get("https://api.instagram.com/v1/users/search?q=#{name}&client_id=#{ENV["INSTAGRAM_CLIENT_ID"]}&client_secret=#{ENV["INSTAGRAM_CLIENT_SECRET"]}")
raise InstagramError.new(response) if !response.success?
user = response.parsed_response["data"].find { |user| user["username"] == name }
end
Expand All @@ -175,7 +156,7 @@ def httparty_error(r)
get %r{/instagram/(?<user_id>\d+)(/(?<username>.+))?} do |user_id, username|
@user_id = user_id

response = HTTParty.get("https://api.instagram.com/v1/users/#{user_id}/media/recent?access_token=#{ENV["INSTAGRAM_ACCESS_TOKEN"]}")
response = HTTParty.get("https://api.instagram.com/v1/users/#{user_id}/media/recent?client_id=#{ENV["INSTAGRAM_CLIENT_ID"]}&client_secret=#{ENV["INSTAGRAM_CLIENT_SECRET"]}")
if response.code == 400
# user no longer exists or is private, show the error in the feed
@meta = response.parsed_response["meta"]
Expand Down
4 changes: 1 addition & 3 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@
</form>
<% end %>
<% if ENV["INSTAGRAM_ACCESS_TOKEN"] %>
<% if ENV["INSTAGRAM_CLIENT_ID"] and ENV["INSTAGRAM_CLIENT_SECRET"] %>
<form class="input-group" method="get" action="/instagram" target="_self">
<div class="input-group-addon"><label for="instagram_q">Instagram</label></div>
<input class="form-control" type="search" name="q" id="instagram_q" placeholder="Enter an Instagram username or a url to a user or post.">
<span class="input-group-btn">
<input class="btn btn-primary" type="submit" value="Get RSS Feed">
</span>
</form>
<% elsif ENV["INSTAGRAM_CLIENT_ID"] and ENV["INSTAGRAM_CLIENT_SECRET"] %>
<a class="btn btn-primary" href="/instagram/auth">Authenticate Instagram</a>
<% end %>


Expand Down

0 comments on commit 2130a1f

Please sign in to comment.