skip to Main Content

I’m currently using the Python SDK for Facebook Ads, mainly to automate reporting on performance based metrics, such as impressions, amount spent, etc. at an ad level for a monthly basis. According to the documentation, it seems like amount_spent is only at an AdAccount level, while most metrics I’m looking for are not even available.

Is it possible to create Ads Manager reports with this API? If I’m not mistaken, it’s supposed to be the facebookads library.

2

Answers


  1. I think what you are looking for are insights. Something like:

    adcampaign = AdCampaign('<AD_CAMPAIGN_GROUP_ID>')
    ads = adcampaign.get_ads(...)
    
    for ad in ads:
        insights = ad.get_insights(fields=['impressions', 'spend', ...])
    

    I don’t use this API or have access to it, so I can’t test it. This piece of code is from looking at the documentation and the source code. Please let me know if this helps.

    Interesting links:

    Login or Signup to reply.
  2. This is the code I currently use to pull data from insights with Facebook marketing api. If this is something you are looking for. Just place your table in the foreach loop and change some colors in your css file and you can have something similar to Facebook Ads Manager.

    $account = new AdAccount('act_xxxxxxxxxxxxx');
    
        $params = array(
          'time_range' => array(
            'since' => (new DateTime($beginDate))->format('Y-m-d'),
            'until' => (new DateTime($lastDate))->format('Y-m-d'),
          ),
    
          'level' => 'ad',
          'limit' => '15'
        );
    
    $fields = array(
      AdsInsightsFields::CAMPAIGN_NAME,
      AdsInsightsFields::CAMPAIGN_ID,
      AdsInsightsFields::IMPRESSIONS,
      AdsInsightsFields::UNIQUE_CLICKS,
      AdsInsightsFields::REACH,
      AdsInsightsFields::SPEND,
      AdsInsightsFields::TOTAL_ACTIONS,
    );
    
    $insights = $account->getInsights($fields, $params);
    
    foreach($insights as $i){
    $i->campaign_id;
    etc.
    etc.
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search