toddwschneider / coordstagram

Instagram viewer by latitude and longitude. Easy to deploy to Heroku
MIT License
218 stars 15 forks source link

Invalid Access Token Error During Configuration #2

Closed IsaacBell closed 6 years ago

IsaacBell commented 8 years ago

Whether deploying manually or using the Heroku deployment template, Heroku eventually throws an Instagram API error during configuration. Instagram returns a 400 error, asking for an access token. From what I can tell, this is a result of Instagram's platform update.

Here's the error (here I'm using the Heroku deploy template, but building manually gives the same error):

fetching 20 page(s) from Instagram, starting at 2015-11-19 14:08:24 UTC and working backward
2015-11-19 14:08:24 UTC 2015-11-19 14:08:24 UTC
** [NewRelic][11/19/15 14:08:24 +0000 run.* (8)] INFO : Reporting to: https://rpm.newrelic.com/accounts/1154242/applications/11053636
rake aborted!
Instagram::BadRequest: GET https://api.instagram.com/v1/media/search.json?client_id=removed&distance=50.0&lat=33.7570174&lng=-84.410121&max_timestamp=1447942104: 400: The access_token provided is invalid.
/app/vendor/bundle/ruby/2.2.0/gems/instagram-1.1.4/lib/faraday/raise_http_exception.rb:11:in `block in call'
/app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.1/lib/faraday/response.rb:57:in `on_complete'
/app/vendor/bundle/ruby/2.2.0/gems/instagram-1.1.4/lib/faraday/raise_http_exception.rb:8:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:30:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.1/lib/faraday/response.rb:8:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.1/lib/faraday/request/url_encoded.rb:15:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/instagram-1.1.4/lib/faraday/oauth2.rb:33:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.1/lib/faraday/rack_builder.rb:139:in `build_response'
/app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.1/lib/faraday/connection.rb:377:in `run_request'
/app/vendor/bundle/ruby/2.2.0/gems/faraday-0.9.1/lib/faraday/connection.rb:140:in `get'
/app/vendor/bundle/ruby/2.2.0/gems/instagram-1.1.4/lib/instagram/request.rb:31:in `request'
/app/vendor/bundle/ruby/2.2.0/gems/instagram-1.1.4/lib/instagram/request.rb:9:in `get'
/app/vendor/bundle/ruby/2.2.0/gems/instagram-1.1.4/lib/instagram/client/media.rb:77:in `media_search'
/app/app/models/instagram_item.rb:33:in `fetch'
/app/app/models/instagram_item.rb:37:in `fetch_and_save'
/app/app/models/instagram_item.rb:63:in `block in backfill_items'
/app/app/models/instagram_item.rb:58:in `times'
/app/app/models/instagram_item.rb:58:in `backfill_items'
/app/lib/tasks/initial_backfill.rake:14:in `block in <top (required)>'
Tasks: TOP => initial_backfill
(See full trace by running task with --trace)
** [NewRelic][11/19/15 14:08:24 +0000 run.* (8)] INFO : Starting Agent shutdown

In the code, I'm guessing the correct fix would be simple as requiring an ACCESS_TOKEN env variable and referencing it in the Instagram Item model.

#.env
ACCESS_TOKEN: "my.access.token"
#instagram_item.rb
ACCESS_TOKEN = ENV['ACCESS_TOKEN']
#instagram_item.rb, line 32
opts.reverse_merge!(distance: MAX_DISTANCE_IN_METERS, access_token: ACCESS_TOKEN)

However, that doesn't fix the problem on its own. I tried running initial_backfill.rake with these changes in a manual installation, and the Instagram API spits out this error:

400: This request requires scope=public_content, but this access token is not authorized with this scope. The user must re-authorize your application with scope=public_content to be granted this permissions.

So I'm guessing that any Instagram API Clients created from Nov. 17, 2015 onwards will need to have public content permissions to function properly.

I hope that was all worded clearly. I wish I could give more information, but I don't know a way to investigate further right now seeing as Instagram Permission Reviews aren't available until next month. Still, I hope this is helpful in some way.

toddwschneider commented 8 years ago

Hmm, this certainly sounds like it's related the new Instagram API permissions. I haven't looked closely yet to see what's allowed and what isn't. My tokens are still working, but they might have a grace period for a few months before getting shut off. Will have to look into this to get a better answer

rahidz commented 8 years ago

Am having the same error deploying manually. A ton of Instagram apps were shut down earlier this summer, wouldn't be surprised if this issue is related.

toddwschneider commented 6 years ago

Unfortunately Instagram has deprecated its platform API, added a note to the readme: https://github.com/toddwschneider/coordstagram/pull/3