使用Instagram rubygem和sinatra我能夠通過oauth從小型AngularJS應用程序成功進行身份驗證並使用Instagram API。下面是我的末日應用程序相關的OAuth路線:Instagram API返回一個代碼,但是當請求訪問令牌時,說相同的代碼是無效的
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
然而,試圖使用相同的路線在一個Android應用程序從網頁視圖中進行身份驗證時(取得OAuth /連接,重定向到Instagram的,然後重定向回的OAuth /回調),我收到以下錯誤:
Instagram::BadRequest - POST https://api.instagram.com/oauth/access_token/: 400: OAuthException: No matching code found.:
我覈實,我使用Instagram的距離,而且REDIRECT_URI返回相同的代碼是一樣的我與Instagram的註冊。
請注意,Oauth在我使用我的Web界面時工作,但不通過Android webview。
我讀了一些,而其他人都看到了這種行爲的帖子,但所提供的解決方案並沒有爲我工作:
,因爲它認爲這是行爲不端的Instagram可以禁用應用程序。不,因爲oauth通過我的web界面工作,仍然使用相同的客戶端ID和祕密路由。
您沒有使用與Instagram中列出的相同的redirect_uri。我已經檢查並重新檢查了這一點,它看起來很好。
我在哪裏可以調試下一個問題到底?
是的,Android WebView onPageFinished回調被觸發兩次,我正在發起兩個身份驗證呼叫。 – cacciatc 2015-02-19 18:13:18