(#2635) 您正在调用已弃用的广告版本 API。请更新到最新版本

(#2635) You are calling a deprecated version of the Ads API. Please update to the latest version

所以有很多类似的问题,虽然我还没有找到任何一个的答案,所以我们来了。我正在尝试使用 Python 从 Facebook API 提取一些数据,这是我收到的错误:

facebook_business.exceptions.FacebookRequestError: 

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v10.0/[hidden]/ads
  Params:  {'summary': 'true'}

  Status:  400
  Response:
    {
      "error": {
        "message": "(#2635) You are calling a deprecated version of the Ads API. Please update to the latest version: v11.0.",
        "type": "OAuthException",
        "code": 2635,
        "fbtrace_id": "[hidden]"
      }
    }

我直接前往我的 Facebook 个人资料中的应用程序设置,看起来像(图片相关)

请注意,在错误消息中,路径中有 v10.0,在应用配置文件中的任何更改 API 版本之前是 v7.0,这很奇怪,是还有其他一些 API 也需要切换版本吗?将那个切换到 v12.0(或当时的 v11.0)没有帮助,所以我真的不知道该怎么做了。

另一个重要的注意事项是,此代码是 Matillion 中预定作业的一部分,并且在版本切换后,如果 运行 在本地,代码实际上会 return 数据,所以我的另一个预感是还需要对 Matillion 环境实施一些更改。

代码如下所示:

from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adreportrun import AdReportRun
import time
from io import StringIO
import json
import boto3

access_token = [hidden]
app_secret = [hidden]
app_id = [hidden]


FacebookAdsApi.init(app_id, app_secret, access_token)

fb_account = AdAccount('[hidden]')

params = {'time_range': {'since': '2022-01-05', 'until': '2022-01-06'},
            'level':'ad',
            'action_breakdowns':['action_device','action_type'],
            'TimeIncrement':1,
             }
fields = [<a pretty big list of fields>]

ads=fb_account.get_ads()
async_job = fb_account.get_insights(params = params, fields = fields,is_async=True)
async_job.api_get()

while async_job[AdReportRun.Field.async_status] != 'Job Completed' or async_job[AdReportRun.Field.async_percent_completion] < 100:
        time.sleep(1)
        async_job.api_get()
time.sleep(1)
responce=async_job.get_result()


print(response)

如果我忘记提及一些细节,请随时提出任何问题,谢谢!

您正在使用的 Facebook Python 模块默认不会随 Matillion 安装。我想肯定有人通过关注 this Matillion guide 安装了它们?也许它是很久以前完成的,在这种情况下,您可能只需要重新安装与更新的 Facebook 通信的最新版本的模块 API.

作为 Python 的替代方案,您还可以查看 Facebook Ads Query component which is a top-level Matillion orchestration component that does not require any coding in Python. According to the docs it uses V11 of the API. Provided the data you need is in that component's data model,总体而言,它的工作量可能比手动编码少。