将图API中的Facebook访问令牌的有效期延长到2个月以上 [英] Extending expiry date of facebook access token in graph api beyond 2 months
问题描述
我正在使用python进行facebook页面墙贴自动化
我已经通过使用 facebook graph api post 在我拥有的fb页面上自动发布了信息 因此,我通过将HTTP POST请求发送到 https://graph.facebook.com/mypagename/feed 来做到这一点>
具有access_token和消息作为POST参数
我通过使用 图形api资源管理器 来生成访问令牌,方法是选择我正在使用的应用程序,并授予其管理我的页面的权限
最初,access_token使用将在2个小时后失效
要将有效期延长至2个月,我将HTTP GET请求发送到此url
响应是一个json字符串,具有 new access_token 和 expiry 时间(以秒为单位)
新访问令牌的到期时间现在为60天.
现在可以将到期时间延长到60天以上吗?
短期和长期令牌
用户访问令牌有两种形式:短期令牌和长期令牌.短期令牌通常的生存期约为一两个小时,而长期令牌通常的生存期约为 60天.您不应依赖这些生存期保持不变-生存期可能会更改,而不会发出警告或提前终止.有关处理错误的更多信息.
所以剩下的唯一方法是在60天之前使用代码重新生成.
发出GET请求以绘制api图形并从JSON响应中过滤出访问令牌
在此处获取您的用户ID http://findmyfacebookid.com/
现在
请求
GET /{user-id}/accounts
响应
{
"data": [
{
"category": "Product/service",
"name": "Sample Page",
"access_token": "{access-token}",
"id": "1234567890",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
},
}
https://developers.facebook.com/docs/facebook-登录/访问令牌#page令牌
I am working on facebook page wallpost automation using python
I have automated posting on a fb page that i own by using facebook graph api post So i do this by sending a HTTP POST request to https://graph.facebook.com/mypagename/feed
with access_token and message as POST paramaters
I generate the access token by using graph api explorer by selecting my app that i am using and giving it permission to manage my pages
Intitially the access_token use to expire in 2 hours
To extend the expiry date to 2 months i send HTTP GET request to this url
the response is a json string with new access_token and expiry time in seconds
the expiry time of new access token is now 60 days.
Now is it possible to extend expiry time beyond 60 days??
Short-Term and Long-Term Tokens
User access tokens come in two forms: short-lived tokens and long-lived tokens. Short-lived tokens usually have a lifetime of about an hour or two, while long-lived tokens usually have a lifetime of about 60 days. You should not depend on these lifetimes remaining the same - the lifetime may change without warning or expire early. See more under handling errors.
So the only way left is to regenerate using code just before 60 days.
Make a GET request to graph api and filter out the access token from the JSON response
Get your user id here http://findmyfacebookid.com/
Now
Request
GET /{user-id}/accounts
Response
{
"data": [
{
"category": "Product/service",
"name": "Sample Page",
"access_token": "{access-token}",
"id": "1234567890",
"perms": [
"ADMINISTER",
"EDIT_PROFILE",
"CREATE_CONTENT",
"MODERATE_CONTENT",
"CREATE_ADS",
"BASIC_ADMIN"
]
},
}
https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens
这篇关于将图API中的Facebook访问令牌的有效期延长到2个月以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!