【问题标题】:Instagram.get_access_token returns BadRequestInstagram.get_access_token 返回 BadRequest
【发布时间】:2013-10-01 18:28:25
【问题描述】:

我正在尝试使用 Instagram gem 对用户进行身份验证。所以我有一个由instagram 返回的带有code 参数的页面,我只需要通过POST 请求将其发回即可。根据 gem 文档,我需要执行以下操作:

get "/oauth/callback" do
  response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL)
  session[:access_token] = response.access_token
  redirect "/feed"
end

所以我有

  def authenticate
    response = Instagram.get_access_token(params[:code], :redirect_uri => "http://127.0.0.1:3000")
    session[:access_token] = response.access_token
    redirect "/feed"
  end

我得到了

Completed 500 Internal Server Error in 957ms

Instagram::BadRequest (POST https://api.instagram.com/oauth/access_token/: 400):
  app/controllers/instagram_controller.rb:25:in `authenticate'

我尝试根据 Instagram api 文档发出 curl 请求,它使用相同的参数。

关于 client_id,我将这些键存储在 instagram.rb 的初始化程序中,所以看起来像

require "instagram"

Instagram.configure do |config|
  config.client_id = "123345"
  config.client_secret = "123123"
end

CALLBACK_URL = "http://127.0.0.1:3000"

非常感谢。

【问题讨论】:

  • 以防万一它有用,here's 我是如何实现 Instagram 的(它所指的 INSTAGRAM_ACCESS_TOKEN 设置在 environment.rb - 这样如果 Instagram 已经设置好了,它无法重新认证)。

标签: ruby-on-rails ruby authentication oauth instagram


【解决方案1】:

发现问题。所以,我也在我的应用程序中进行了设计,我没有在 config.omniauth 中放入“redirect_url”。人们在这里谈论的完全一样的事情https://github.com/Instagram/instagram-ruby-gem/issues/22。 感谢您的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2015-10-10
    • 2022-08-17
    • 2021-08-29
    相关资源
    最近更新 更多