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