所以我正在努力学习如何使用Facebook API。我需要创建一个脚本,每天将我的业务广告系列的信息下载为csv文件,以便我可以使用另一个脚本轻松地将信息上传到我们的数据库。
我终于有了可用于将信息打印到日志中的代码,但由于我必须为每个广告系列单独调用get_insights()方法,因此我已经达到了用户请求限制。我想知道是否有人知道如何帮助我减少调用Facebook API的频率。
如果可能的话,我想找到一个可以获取每日花费的字段,这样我就不必在每次广告系列循环迭代中都调用API,但是我无论如何都找不到方法。
#Import all the facebook mumbo jumbo
from facebookads.api import FacebookAdsApi
from facebookads.adobjects.adset import AdSet
from facebookads.adobjects.campaign import Campaign
from facebookads.adobjects.adsinsights import AdsInsights
from facebookads.adobjects.adreportrun import AdReportRun
from facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.business import Business
import time
#Set the login info
my_app_id = '****'
my_app_secret = '****'
my_access_token = '****'
#Start the connection to the facebook API
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
business = Business('****')
#Get all ad accounts on the business account
accounts = business.get_owned_ad_accounts(fields=[AdAccount.Field.id])
#iterate through all accounts in the business account
for account in accounts:
tempaccount = AdAccount(account[AdAccount.Field.id])
#get all campaigns in the adaccount
campaigns = tempaccount.get_campaigns(fields=[Campaign.Field.name,Campaign.Field])
#iterate trough all the campaigns in the adaccount
for campaign in campaigns:
print(campaign[Campaign.Field.name])
#get the insight info (spend) from each campaign
campaignsights = campaign.get_insights(params={'date_preset':'yesterday'},fields=[AdsInsights.Field.spend])
print (campaignsights)
信息:调用不成功 方法:GET 路径:https://graph.facebook.com/v2.11/act_**********/owned_ad_accounts 参数:{'fields': 'id', 'summary': 'true'} 状态:400 响应: { "error": { "message": "(#2635) You are calling a deprecated version of the Ads API. Please update to the latest version: v8.0.", "type": "OAuthException", "code": 2635, "fbtrace_id": "***********" } }
- Mohamed Azizi