gpt4 book ai didi

ruby-on-rails-3 - 使用考拉更新 Facebook 访问 token

转载 作者:行者123 更新时间:2023-12-03 13:31:31 25 4
gpt4 key购买 nike

我正在使用 Koala Ruby on Rails 应用程序上的 gem

我在通过考拉使用数据的模型上有以下代码:

@graph = Koala::Facebook::GraphAPI.new(token_secret)
friends = @graph.get_connections("me", "friends")

在哪里 token_secret来自我的 users 的一个领域表,登录时保存。

它工作正常,但几分钟后我得到:
Koala::Facebook::APIError (OAuthException: Error validating access token: Session has expired at unix time 1327438800. The current unix time is 1327442037.):

我在前面找到了使用 Facebook JS SDK 中的方法更新此 token 的方法但是在 Controller 上调用了我获取 friend 列表的这种方法。

如何续订 token_secret使用考拉?这可能吗?

最佳答案

我想我会回答这个问题,因为这是我刚刚遇到需要做的事情。

Koala 前段时间在此处添加了对交换访问 token 的支持:
https://github.com/arsduo/koala/pull/166

所以我的用户模型现在有如下内容:

def refresh_facebook_token
# Checks the saved expiry time against the current time
if facebook_token_expired?

# Get the new token
new_token = facebook_oauth.exchange_access_token_info(token_secret)

# Save the new token and its expiry over the old one
self.token_secret = new_token['access_token']
self.token_expiry = new_token['expires']
save
end
end

# Connect to Facebook via Koala's oauth
def facebook_oauth
# Insert your own Facebook client ID and secret here
@facebook_oauth ||= Koala::Facebook::OAuth.new(client_id, client_secret)
end

关于ruby-on-rails-3 - 使用考拉更新 Facebook 访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8995035/

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