简体   繁体   English

Rails 4 / Koala:如何刷新长时间访问令牌?

[英]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-idclient-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.

相关问题 Rails,Koala:facebook访问令牌即将过期,如何使其更长 - Rails, Koala: facebook access token expires very soon, how to make it longer 使用 Koala 和 Ruby on Rails 获取 Facebook 应用访问令牌 - Obtain a Facebook app access token using Koala and Ruby on Rails 使用Koala和Rails获取应用程序用户访问令牌 - Get App user access token using Koala and Rails Rails - Facebook与Omniauth和Koala:如何续订过期的令牌 - Rails - Facebook with Omniauth and Koala: How to renew an expired token 如何在Koala,Ruby on Rails中发送私人消息/访问Facebook聊天 - How to send private message/access facebook chat in Koala ,Ruby on Rails 在 Rails 应用程序中实现考拉 gem 时未定义的方法“get_access_token” - undefined method `get_access_token' while implementing koala gem in rails app 如何通过带有KOALA gem的访问令牌传递Facebook的供稿和帖子的实时更新 - How to pass an access token with KOALA gem for facebook real time updates for feeds and posts 尝试使用Koala进行fb apprequest,但访问令牌已过期。 我应该怎么处理? - Trying to do a fb apprequest using Koala but access token expired. How should I handle? 如何使用来自SERVER(!)的Koala Gem更新/延长Facebook访问令牌,完全没有用户交互 - How to renew/prolong Facebook access token with Koala Gem from SERVER (!) with NO users interaction at all Rails Google Client API - 无法为访问令牌交换刷新令牌 - Rails Google Client API - unable to exchange a refresh token for access token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM