Reputation: 1
I want to write query in Python, I want all ads performance details in single request or many request. I'd tried using below queries, but it is wrong idea to send multiple times to send request to Facebook, and also Facebook blocks User for 30 minutes.
my_app_id = 'my_app_id'
my_app_secret = 'my_app_secret'
my_access_token = 'my_token'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount('act_')
ad_campaign_list = my_account.get_campaigns(fields=[Campaign.Field.name,Campaign.Field.id])
for campaign in ad_campaign_list:
campaign_index=Campaign(campaign["id"])
ad_setlist = campaign_index.get_ad_sets(fields=[AdSet.Field.name,AdSet.Field.id])
for ad_set in ad_setlist:
print(ad_set)
ad_set_index = AdSet(ad_setlist["id"])
ad_list = ad_set_index.get_ads(fields=[Ad.Field.name,Ad.Field.id])
for ad in ad_list:
print(ad)
I have a error like
Message: Call was not successful
Method: GET
Path: https://graph.facebook.com/v9.0/act_/ad
Params: {'fields': 'name,id', 'summary': 'true'}
Status: 400
Response:
{
"error": {
"message": "(#17) User request limit reached",
"type": "OAuthException",
"is_transient": true,
"code": 17,
"error_subcode": 2446079,
"fbtrace_id": "Al42-tg1iVmvfE79RVrGDJW"
}
}
I think to use to
my_app_id = 'my_app_id'
my_app_secret = 'my_app_secret'
my_access_token = 'my_token'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount('act_')
ad = my_account.get_ads(fields=[Ad.Field.name,Ad.Field.id])
print(ad)
but i don't have all my ad
Upvotes: 0
Views: 1904
Reputation: 152
You have a limit of requests you can do with the Graph API. To know more about limits, check this link, but in summary, you can make this amount of calls:
To avoid this issue, I suggest you to, instead of passing the fields the way you are doing, to pass them like this:
report = facebook_acc.get_campaigns(fields=['name,adsets{id,ads{id,name}}'])
This way you can get all ads info in on single query.
Upvotes: 1