[英]Rails 4 / Koala: how to refresh long access token?
Using Rails 4 and Koala gem version 2. I have my personal Facebook page (not profile). 使用Rails 4和Koala gem版本2。我有我的个人Facebook 页面 (不是个人资料)。 When I am publishing a new post in my website I want to automatically publish it on my facebook page as well.
当我在网站上发布新帖子时, 我也想自动将其发布在我的 Facebook页面上。 I am using Koala gem but I have some problem with access tokens.
我正在使用Koala gem,但是访问令牌存在一些问题。
Visiting https://developers.facebook.com/tools/explorer/ I get a short-live token. 访问https://developers.facebook.com/tools/explorer/我得到了一个短期令牌。 This token expires after only 2 hours.
此令牌仅在2小时后过期。
My goal is to obtain a long-live token. 我的目标是获得一个长期的令牌。 I have created a new Facebook app and I have obtained a client-id and client-secret .
我创建了一个新的Facebook应用程序,并获得了一个client-id和client-secret 。
Visiting this https://graph.facebook.com/oauth/access_token?client_id=MY-CLIENT-ID&client_secret=MY-CLIENT-SECRET&grant_type=fb_exchange_token&fb_exchange_token=MY-SHORT-LIVE-TOKEN I get long-live token. 访问此https://graph.facebook.com/oauth/access_token?client_id=MY-CLIENT-ID&client_secret=MY-CLIENT-SECRET&grant_type=fb_exchange_token&fb_exchange_token=MY-SHORT-LIVE-TOKEN我得到了长期有效的令牌。
Now I can use my long-live token to publish on my page: 现在,我可以使用我的长期令牌在我的页面上发布:
user = Koala::Facebook::API.new long_live_access_token
page_access_token = user.get_connections('me', 'accounts').first['access_token']
page = Koala::Facebook::API.new page_access_token
page.put_connections("me", "feed", message: "I am posting on my page!ok!")
It seems to work, but my problems is that the long-live token expires in 60 days so I need to refresh it. 它似乎可以正常工作,但是我的问题是长效令牌会在60天后过期,因此我需要刷新它。 I have found no solution to refresh a long-live token.
我没有找到刷新长效令牌的解决方案。 It is clear that I can't repeat the entire procedure every 60 days!
很明显,我不能每60天重复一次整个过程!
Ideas? 有想法吗?
From the official docs: 从官方文档:
These tokens ( long-lived ) will be refreshed once per day when the person using your app makes a request to Facebook's servers.
当使用您的应用的用户向Facebook的服务器发出请求时,这些令牌( 长期有效 )将每天刷新一次。 If no requests are made, the token will expire after about 60 days and the person will have to go through the login flow again to get a new token.
如果没有请求,令牌将在约60天后过期,该人将不得不再次通过登录流程来获取新令牌。
The token that never expires is a page token. 永不过期的令牌是页面令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.