【发布时间】: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