2

我正在尝试使用 Instagram gem 对用户进行身份验证。所以我有一个带有codeinstagram 返回参数的页面,我只需要使用 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"

提前非常感谢。

4

1 回答 1

2

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

于 2013-10-02T18:58:38.140 回答