简体   繁体   中英

How to get insights for all Ad in single query with Facebook marketing api

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

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:

  • Calls within one hour = 200 * Number of Users

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM