【发布时间】:2015-02-11 00:39:17
【问题描述】:
使用 Instagram rubygem 和 sinatra,我能够从一个小型 AngularJS 应用程序通过 oauth 成功进行身份验证,并使用 Instagram API。以下是我的 sinatra 应用程序中的相关 oauth 路由:
get '/oauth/connect' do
logger.info "going here " + (Instagram.authorize_url :redirect_uri => CALLBACK)
redirect Instagram.authorize_url :redirect_uri => CALLBACK
end
get "/oauth/callback" do
logger.info params[:code]
response = Instagram.get_access_token params[:code], :redirect_uri => CALLBACK
session[:access_token] = response.access_token
users = DB[:users]
current_user = users[:instagram_id => response.user.id.to_i]
if current_user.nil?
new_user = response.user
users.insert :instagram_id => new_user.id.to_i,
:username => new_user.username,
:profile_picture => new_user.profile_picture,
:created_at => DateTime.now
current_user = users[:instagram_id => new_user.id]
end
session[:current_user] = current_user
redirect "/app"
end
但是,当尝试使用相同的路由(GET oauth/connect,重定向到 Instagram,然后重定向回 oauth/callback)从 Android 应用程序的 webview 中进行身份验证时,我收到以下错误:
Instagram::BadRequest - POST https://api.instagram.com/oauth/access_token/: 400: OAuthException: No matching code found.:
我已确认我使用的是从 Instagram 返回的相同代码,并且 redirect_uri 与我在 Instagram 注册的相同。
注意,Oauth 在我使用网络界面时有效,但不是通过 Android 网络视图。
我阅读了许多其他人看到此行为的帖子,但提供的解决方案对我不起作用:
Instagram 可以禁用您的应用,因为它认为它行为不端。不,因为 oauth 通过我的网络界面工作,仍然使用相同的客户端 ID 和密钥以及相同的路由。
您使用的 redirect_uri 与 Instagram 中列出的不同。我已经检查并重新检查了它,它看起来很好。
接下来我可以在哪里调试以了解此问题的根源?
【问题讨论】:
标签: android ruby oauth instagram