skip to Main Content

I’m building a small program that works with various APIs to automate reporting services we offer some clients.

One of the things we report on is Facebook Ads performance.

I’ve been building out this program using the Facebook Marketing API & Ads Insight APi https://developers.facebook.com/docs/marketing-apis

I’ve gone through the whole process of setting up a Facebook ‘App’ and getting the relevant app tokens.

However, I’ve hit a wall since development access only allows for 5 Ad Accounts.

To apply for basic access, the marketing API is asking for the development platform and a whole bunch of other things that aren’t relevant to my program. I’m not building an ‘app’ intended for public release in the traditional sense; rather, I just want to integrate with these APIs on a basic level to automate some internal tasks.

It seems mind-boggling to me that I wouldn’t be able to do something like this, but this is what the Facebook documentation seems to be suggesting.

If anyone else has familiarity with this kind of issue, I’d love to know if there is a workaround.

2

Answers


  1. Derks, I currently am building dashboard with over 40 clients and I am able to display everyone of them and their insights data etc. with basic development level. I have code if you want to take a look only thing I am trying to accomplish now is making a date range picker but, you are more than welcome enough to take a look at what I have just to get a general idea.

    Here are the Use objects from Facebook

    <?php
    
            require_once __DIR__ . '/vendor/autoload.php';
            use FacebookAdsApi;
            use FacebookAdsObjectAdUser;
            use FacebookFacebook;
            use FacebookExceptionsFacebookResponseException;
            use FacebookExceptionsFacebookSDKException;
            use FacebookAdsObjectCampaign;
            use FacebookAdsObjectFieldsAdsInsightsFields;
            use FacebookAdsObjectAd;
            use FacebookAdsObjectFieldsAdSetFields;
            use FacebookAdsObjectAdCampaign;
            use FacebookAdsObjectFieldsAdFields;
            use FacebookAdsObjectFields;
            use FacebookAdsObjectFieldsAdImageFields;
            use FacebookAdsObjectAdAccount;
            use FacebookAdsObjectAdSet;
            use FacebookAdsObjectAdCreative;
            use FacebookAdsObjectFieldsAdCreativeFields;
            use FacebookAdsObjectFieldsAdCreativePhotoDataFields;
            use FacebookAdsObjectAdCreativeLinkData;
            use FacebookAdsObjectFieldsAdCreativeLinkDataFields;
            use FacebookAdsObjectFieldsCampaignFields;
            use FacebookAdsObjectPage;
            use FacebookAdsObjectFieldsAdPreviewFields;
            use FacebookAdsObjectValuesAdPreviewAdFormatValues;
            use FacebookAdsObjectAdVideo;
            ?>
    
    Here is the general code I am trying
    
    <?php
            // Init PHP Sessions
            session_start();
    
            $fb = new Facebook([
              'app_id' => 'xxxxxxxxx',
              'app_secret' => 'xxxxxxxxxxx',
            ]);
    
            $helper = $fb->getRedirectLoginHelper();
    
            if (!isset($_SESSION['enter api key here'])) {
              $_SESSION['enter api key here'] = null;
            }
    
            if (!$_SESSION['enter api key here']) {
              $helper = $fb->getRedirectLoginHelper();
              try {
                $_SESSION['enter api key here'] = (string) $helper->getAccessToken();
              } catch(FacebookResponseException $e) {
                // When Graph returns an error
                echo 'Graph returned an error: ' . $e->getMessage();
                exit;
              } catch(FacebookSDKException $e) {
                // When validation fails or other local issues
                echo 'Facebook SDK returned an error: ' . $e->getMessage();
                exit;
              }
            }
    
            if ($_SESSION['enter api key here']) {
              //echo "You are logged in!";
    
            // Initialize a new Session and instantiate an API object
            Api::init(
              'xxxxxxxxx', // App ID
              'xxxxxxxxx', //app_secret
              $_SESSION['enter api key here'] // Your user access token
            );
    
        ?>
    <div id="fbdata"></div> <?php
    
        $account = new AdAccount('act_xxxxxxxxxx');
    
    
            $params = array(
    
            'date_preset'=> 'last_28d',
    
    
                'thumbnail_width' => 200,
                'thumbnail_height' => 150,
                'level' => 'campaign',
                'limit' => '15'
    
            );
    
    $fields = array(
      AdsInsightsFields::CAMPAIGN_NAME,
      AdsInsightsFields::CAMPAIGN_ID,
      AdsInsightsFields::IMPRESSIONS,
      AdsInsightsFields::CLICKS,
      AdsInsightsFields::REACH,
      AdsInsightsFields::SPEND,
      AdsInsightsFields::CPM,
      AdsInsightsFields::CPC,
      AdsInsightsFields::ACTIONS, 
    );
    
    $field = array(
      AdCreativeFields::TITLE,
      AdCreativeFields::THUMBNAIL_URL,
      AdCreativeFields::BODY,
      );
    
                $params1 = array(
              'time_range' => array(
                'since' => (new DateTime($beginDate))->format('Y-m-d'),
                'until' => (new DateTime($lastDate))->format('Y-m-d'),
              ),
                'thumbnail_width' => 200,
                'thumbnail_height' => 150,
                'level' => 'ad',
                'limit' => '5'
            );      
    
    $adcreatives = $account->getAdCreatives($field, $params1);
    ?>      
            <table class="fbtable">
                <tr>
                    <th>Title</th>
                    <th>Ad Image</th>
                    <th>Ad Body</th>
                </tr>
                <?php
    foreach($adcreatives as $t2){
    
            echo"<tr>
            <td>$t2->title</td>
          <td><img src='$t2->thumbnail_url'/></td>
          <td>$t2->body</td>
        </tr>";
    }
    
            $insights = $account->getInsights($fields, $params);?>
    
            <table class="fbtable">
                <tr>
                    <th>Campaign ID</th>
                    <th>Campaign Name</th>
                    <th>Impressions</th>
                    <th>Clicks</th>
                    <th>Reach</th>
                    <th>Spend</th>
                    <th>Total Actions</th>
                    <th>CPM</th>
                    <th>CPC</th>
                </tr>
    
                <?php
    
    foreach($insights as $i) {
        $impress = number_format((float)$i->impressions);
        $reach = number_format((float)$i->reach);
        $totalAction = number_format((float)$i->actions);
        $cpc = number_format($i->cpc, 2, '.', '');
        $cpm = number_format($i->cpm, 2, '.', '');
        echo"<tr class='fbtable'>
          <td>$i->campaign_id</td>
          <td>$i->campaign_name</td>
          <td>$impress</td>
          <td>$i->clicks</td>
          <td>$reach</td>
          <td>$$i->spend</td>
          <td>$totalAction</td>
          <td>$$cpm</td>
          <td>$$cpc</td>
        </tr>";
    }
            }else {
              $permissions = ['ads_management'];
              $loginUrl = $helper->getLoginUrl('http://where you want login to be.com', $permissions);
              echo '<a href="' . $loginUrl . '">Log in with Facebook</a>';
            } 
    
    
    ?>
    

    I will help much as I can @Derks and I believe the only thing you may need to do is figure out way for the program or whatever your building know who is who.

    Login or Signup to reply.
  2. Submit your app for review to get more than 10 ad accounts. Use the “Platform” of Website. Select Native or desktop app; app secret NOT embedded in the client. The rest of it can be mostly ignored, but you will need to include some screen shots of your app and a description of how it works and what it does. A real human will review it, and you can get help in the Facebook Developers group here:
    https://www.facebook.com/groups/fbdevelopers

    Youwill get a pass/fail only…no comments. Don’t be surprised if they reject it first time around. Do not resubmit and hope for a better response the second time around — they’ll eventually lock you out for a few days. Post a help question to the group.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search