gpt4 book ai didi

python - v2.4 及更高版本已弃用 adaccount/reportstats

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:32 25 4
gpt4 key购买 nike

我正在尝试遵循 Python Facebook Marketing Api 中的一些示例但是,当我运行时:

i_async_job = account.get_insights(params={'level': 'adgroup'}, async=True)
r_async_job = account.get_report_stats(
params={
'data_columns': ['adgroup_id'],
'date_preset': 'last_30_days'
},
async=True
)

我懂了

Status:  400
Response:
{
"error": {
"message": "(#12) adaccount/reportstats is deprecated for versions v2.4 and higher",
"code": 12,
"type": "OAuthException"
}
}

甚至来自 Facebook

我找到了这个page ,但只有curl示例。

是否有关于如何使用 Python Ads API 从 Insights Edge 获取数据的有效示例?

最佳答案

以下是如何从新的 Insights 端点异步导出一些见解的完整示例:

from facebookads import test_config as config
from facebookads.objects import *
import time

account_id = <YOUR_ACCOUNT_ID>
account_id = 'act_' + str(account_id)

fields = [
Insights.Field.impressions,
Insights.Field.clicks,
Insights.Field.actions,
Insights.Field.spend,
Insights.Field.campaign_group_name,
]

params = {
'date_preset': Insights.Preset.last_7_days,
'level': Insights.Level.adgroup,
'sort_by': 'date_start',
'sort_dir': 'desc',
}

ad_account = AdAccount(account_id)
job = ad_account.get_insights(fields=fields, params=params, async=True)
insights = None

while insights is None:
time.sleep(1)
job.remote_read()
completition = job[AsyncJob.Field.async_percent_completion]
print("Percent done: " + str(completition))
if int(completition) is 100:
insights = job.get_result(params={'limit': 100})


for ad_insight in insights:
print(ad_insight)

关于python - v2.4 及更高版本已弃用 adaccount/reportstats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31909794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com