gpt4 book ai didi

ruby-on-rails - Instagram Omniauth on Rails invalid_credentials

转载 作者:数据小太阳 更新时间:2023-10-29 08:43:29 24 4
gpt4 key购买 nike

我已经将 instagram omniauth 集成工作了几年,很长一段时间我都没有改变任何东西,但我的客户在连接他们的 Instagram 帐户时偶尔会突然出现错误:

Started GET "/auth/instagram/callback?code=d3b1c4d88e2f440b8a8a98037b821c15&state=2565d32ecd3cc5967f32d8c945db6ffba74dc784100777f2" for 127.0.0.1 at 2016-12-15 15:29:59 -
0800
I, [2016-12-15T15:29:59.276712 #32520] INFO -- omniauth: (instagram) Callback phase initiated.
E, [2016-12-15T15:29:59.519801 #32520] ERROR -- omniauth: (instagram) Authentication failure! invalid_credentials: OAuth2::Error, :
{"code": 400, "error_type": "OAuthException", "error_message": "Matching code was not found or was already used."}

我能一直做到这一点的唯一方法是从我的应用程序连接帐户,然后从 instagram 端删除权限,然后尝试在我的应用程序上再次重新连接,但似乎我的一些客户正在接受这个他们第一次连接他们的 Instagram 帐户。

有人遇到过这个吗?我的 config/initializers/omniauth.rb 看起来像这样:

Rails.application.config.middleware.use OmniAuth::Builder do
provider :instagram, ENV['INSTAGRAM_CLIENT_ID'], ENV['INSTAGRAM_CLIENT_SECRET'], scope: 'basic comments public_content'
end

编辑:

我正在使用 omniauth 1.3.1 和 omniauth-instagram 1.0.2

我的路线只是您的基本 omniauth 路线:

 get '/auth/:provider/callback', to: 'omniauth_callbacks#create'

我的 Controller 操作有点复杂,但它看起来像这样:

class OmniauthCallbacksController < ApplicationController

def create
if user_signed_in?
social_account = SocialAccount.from_omniauth(auth_params, current_user)
social_account.save!
redirect_to root_path
else
user = User.from_omniauth auth_params
sign_in_and_redirect user
end
end

private

def auth
request.env['omniauth.auth']
end

def auth_params
{
provider: auth['provider'],
uid: auth['uid'],
token: auth['credentials']['token'],
secret: auth['credentials']['secret'] || auth['credentials']['refresh_token'],
name: auth['info']['nickname'] || auth['info']['name'],
emails_sent: 0
}
end
end

基本上,它会创建一个新用户并在他们尚未连接时让他们登录,如果他们已经连接,它会更新他们的登录信息。

最佳答案

在 Instagram 上获取访问 token 似乎存在问题。 https://news.ycombinator.com/item?id=13178789

关于ruby-on-rails - Instagram Omniauth on Rails invalid_credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41175074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com