gpt4 book ai didi

ruby-on-rails - 混合使用 omniauth 和 fbgraph gems 时,我无法获得访问 key

转载 作者:行者123 更新时间:2023-11-30 05:25:48 25 4
gpt4 key购买 nike

我正在使用 Rails 3。当我尝试获取访问 key 时,我在 SessionsController#create 错误中收到 Rack::OAuth2::Client::Error 错误。我使用 omniauth 登录到 facebook,我得到了参数 ["code"]现在,我尝试使用 fbgraph 获取访问代码,但我收到了 Rac::OAuth2::Client::Error。

  def create
auth=request.env["omniauth.auth"]
fb_auth=FbGraph::Auth.new("xxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
client=fb_auth.client
client.redirect_uri="http://localhost:3000/facebook/callback/"
client.authorization_code=params[:code]
access_token = client.access_token! # => Rack::OAuth2::AccessToken
user=User.find_by_provider_and_uid(auth["provider"], auth["id"]) ||User.create_with_omniauth(auth, access_token)
session[:user_id]=user.id

redirect_to root_url, :notice => "Signed In!"
end

access_token!行是返回错误的内容。

最佳答案

如果您在 fb_auth 而不是客户端上设置 redirect_uri 应该没问题,例如

fb_auth = FbGraph::Auth.new(
"xxxxxxx",
"xxxxxxxxxxxxxxxxxxxxxxxxxxx",
:redirect_uri = "http://localhost:3000/facebook/callback"
)
client=fb_auth.client
client.authorization_code=params[:code]
access_token = client.access_token! # => Rack::OAuth2::AccessToken

您还应该查看 https://github.com/nov/fb_graph/issues/127#issuecomment-2244499 ,然后阅读 fb_graph_sample 代码并设置 FbGraph 调试。

关于ruby-on-rails - 混合使用 omniauth 和 fbgraph gems 时,我无法获得访问 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6525303/

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