gpt4 book ai didi

facebook-marketing-api - 如何使用 Facebook-business-python-sdk 从 Facebook 的 insights api 获得超过 25 个结果?

转载 作者:行者123 更新时间:2023-12-02 16:54:50 29 4
gpt4 key购买 nike

我正在尝试使用 facebook-python-business-sdk 从 Facebook 的洞察 API 获取基本的广告级别数据使用 python 3.7。问题是我只返回 25 个结果,即使在拥有超过 25 个有效广告的帐户中也是如此。

我在每个帐户上使用 get_insights 方法,传递 'level':'ad' 参数并在特定日期进行过滤。我还检查了我是否已达到 facebook 的限制(使用提供的解释 here )并且我什至没有接近限制。get_insights 方法没有“限制”参数,无论哪种方式我都不想限制它,因为某些帐户可能有数百甚至数千个广告。

这是我正在使用的代码

from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adaccountuser import AdAccountUser
from facebook_business.adobjects.campaign import Campaign as AdCampaign
from facebook_business.adobjects.adsinsights import AdsInsights

access_token = '******'
app_secret = '******'
app_id = '******'

FacebookAdsApi.init(app_id, app_secret, access_token)

me = AdAccountUser(fbid='me')
my_accounts = list(me.get_ad_accounts())

params={'time_range': {'since': '2019-06-29', 'until': '2019-06-29'},'level': 'ad'}
fields = [AdsInsights.Field.account_id,
AdsInsights.Field.account_name,
AdsInsights.Field.ad_id,
AdsInsights.Field.ad_name,
AdsInsights.Field.adset_id,
AdsInsights.Field.adset_name,
AdsInsights.Field.campaign_id,
AdsInsights.Field.campaign_name,
AdsInsights.Field.spend,
AdsInsights.Field.impressions,
AdsInsights.Field.clicks,
AdsInsights.Field.outbound_clicks,
]

for account in my_accounts:
ads = account.get_insights(params=params, fields=fields)
print(ads)
print(len(ads))

我希望获得每个帐户中的所有广告,但每个帐户最多只能获得 25 个广告。任何帮助将不胜感激!

谢谢

最佳答案

解决方案只是添加一个“限制”参数,见下文:

from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adaccountuser import AdAccountUser
from facebook_business.adobjects.campaign import Campaign as AdCampaign
from facebook_business.adobjects.adsinsights import AdsInsights

access_token = '******'
app_secret = '******'
app_id = '******'

FacebookAdsApi.init(app_id, app_secret, access_token)

me = AdAccountUser(fbid='me')
my_accounts = list(me.get_ad_accounts())

params={'time_range': {'since': '2019-06-29', 'until': '2019-06-29'},'level': 'ad', 'limit': '20000'}
fields = [AdsInsights.Field.account_id,
AdsInsights.Field.account_name,
AdsInsights.Field.ad_id,
AdsInsights.Field.ad_name,
AdsInsights.Field.adset_id,
AdsInsights.Field.adset_name,
AdsInsights.Field.campaign_id,
AdsInsights.Field.campaign_name,
AdsInsights.Field.spend,
AdsInsights.Field.impressions,
AdsInsights.Field.clicks,
AdsInsights.Field.outbound_clicks,
]

for account in my_accounts:
ads = account.get_insights(params=params, fields=fields)
print(ads)
print(len(ads))

感谢@Matteo

关于facebook-marketing-api - 如何使用 Facebook-business-python-sdk 从 Facebook 的 insights api 获得超过 25 个结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56865103/

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