如何将 Facebook Ads Insight API 与应用令牌一起使用?

问题描述

我目前正在使用带有用户令牌的 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>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...