将图形 api 中 facebook 访问令牌的到期日期延长至 2 个月以上 [英] Extending expiry date of facebook access token in graph api beyond 2 months
问题描述
我正在使用 python 进行 facebook 页面墙贴自动化
我使用 facebook graph api post 在我拥有的 fb 页面上自动发布所以我通过向 https://graph.facebook.com/mypagename/feed 发送 HTTP POST 请求来做到这一点>
使用 access_token 和 message 作为 POST 参数
我使用graph api explorer生成访问令牌,方法是选择我正在使用的应用并授予其管理我的页面的权限
最初使用的 access_token 会在 2 小时内过期
为了将到期日期延长至 2 个月,我向此网址发送 HTTP GET 请求
<块引用>响应是一个带有 new access_token 和 expiry 时间(以秒为单位)的 json 字符串
新访问令牌的到期时间现在是 60 天.
现在是否可以将到期时间延长到 60 天以上??
Short-Term and Long-Term Tokens
用户访问令牌有两种形式:短期令牌和长期令牌.短期令牌的生命周期通常约为一两个小时,而长期令牌的生命周期通常约为60 天.你不应该依赖这些生命周期保持不变——生命周期可能会在没有警告的情况下改变或提前到期.在处理错误下查看更多信息.
所以剩下的唯一方法是在 60 天之前使用代码重新生成.
向图形 API 发出 GET 请求并从 JSON 响应中过滤掉访问令牌
在此处获取您的用户 ID http://findmyfacebookid.com/
现在
请求
GET/{user-id}/accounts
回复
<代码>{数据": [{"category": "产品/服务","name": "示例页面","access_token": "{access-token}","id": "1234567890",烫发":[管理",编辑个人资料","CREATE_CONTENT","MODERATE_CONTENT","CREATE_ADS",基本_管理员"]},}
https://developers.facebook.com/docs/facebook-登录/访问令牌#pagetokens
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屋!