问题描述
我目前正在使用带有用户令牌的 Facebook Ads Insight API,但此用户令牌会过期(临时令牌每小时一次,扩展令牌每 60 天一次),我需要在我的环境中手动更新它。有没有办法使用应用令牌来永久允许访问 AdsInsight API?否则,刷新用户令牌的编程方式是什么? (仅供参考,我使用 airflow 将令牌存储在 admin/connections 中)
现在我的 URL 请求是:
https://graph.facebook.com/v8.0/act_<SECRET_AD_ACCOUNT_ID>/insights?access_token=<SECRET_TOKEN>=ad_id,ad_name,clicks,unique_clicks,inline_link_clicks,unique_inline_link_clicks&time_range={'since':'2021-01-01','until':'2021-01-05'}&time_increment=1&level=ad
当 <SECRET_TOKEN>
是
使用应用令牌时出错:
{
"error": {
"message": "Unsupported get request. Object with ID 'act_<SECRET_AD_ACCOUNT_ID>' does not exist,cannot be loaded due to missing permissions,or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api","type": "GraphMethodException","code": 100,"error_subcode": 33,"fbtrace_id": "<SECRET>"
}
}
解决方法
用户令牌的有效期为 60 天,但有一种方法可以通过 API 自动更新它们。每
oauth/access_token?grant_type=fb_exchange_token&client_id=<APP_CLIENT_ID>&client_secret=<APP_SECRET>&fb_exchange_token=<USER_TOKEN>