简体   繁体   中英

user limit reach with the facebook marketing API on a dashboard

I am making a bunch of different dashboards that show data from different campaigns.

I am worried about the #17 User request limit reached as I have gotten this quite a couple of times.

I am using the Facebook Marketing API to get Insights for specific campaigns, but I can't figure out why I end up getting to the limit

I am using a single user access token, to avoid users logging in to facebook to view the dashboard.

I use this piece of script to get insights data and store it in MySQL

  Api::init(
                'XXXX',
                'XXXX',             
                'XXXX'
            );

            $api = Api::instance();

            $account = new AdAccount('act_XXXX');

            $campaign_params = array(
                'limit' => 200,
                'time_range' => array(
                    'since' => date("Y-m-d", strtotime($_GET["date_from"])),
                    'until' => date("Y-m-d", strtotime($_GET["date_to"])),
                ),
                'level' => "adset",
            );

            $campaign_res = $account->getInsights(array("ad_name", "adset_name", "adset_id", "inline_link_clicks", "spend", "campaign_id", "campaign_name", "unique_clicks", "cost_per_inline_link_click", "ctr", "cpm", "cpp", "reach", "impressions"), $campaign_params);

            $pagesArray = array();

            foreach($campaign_res as $c_data) {
                $campaign = $c_data->exportData();

                $pos = strpos(utf8_decode($campaign["campaign_name"]), "Mød");

                if($pos !== false) {

                    $chars = array("æ", "ø", "å");
                    $replace = array("ae", "oe", "aa");

                    $decoded_name = strtolower(str_replace($chars, $replace, utf8_decode($campaign["campaign_name"])));
                    $decoded_name = explode(" - ", $decoded_name);

                    $lpage_pos = strripos($decoded_name[0], $_GET["lpage"]);

                    if($lpage_pos !== false) {

                        $adset = new AdSet($campaign["adset_id"]);
                        $adset->read(array(
                          AdSetFields::NAME,
                          AdSetFields::CONFIGURED_STATUS,
                          AdSetFields::EFFECTIVE_STATUS,
                        ));

                        $nameArray = preg_split("/ - /", $campaign["adset_name"]);

                        if(trim(strtolower($nameArray[1])) == "msn") {

                            $status = strtolower($adset->{AdSetFields::EFFECTIVE_STATUS}.PHP_EOL);

                            array_push($pagesArray, array("pageName" => trim(strtolower($nameArray[0])), "pageSpend" => $campaign["spend"]));

                            $delete_sql = "DELETE FROM msn_ad_data WHERE adset_id = ". $campaign["adset_id"] ." AND type='facebook'";
                            $delete_sth = $db->dbh->prepare($delete_sql);
                            $delete_sth->execute();

                            $sql = "INSERT INTO msn_ad_data (campaign_id, campaign_name, adset_id, adset_name, amount_spent, reach, impressions, date_from, date_to, clicks, cpc, ctr, cpm, id_campaign_shortname, pagename, id_name, form_name, status, type) VALUES ( ". $campaign["campaign_id"] .", '". $campaign["campaign_name"] ."', '". $campaign["adset_id"] ."', '". $campaign["adset_name"] ."', '". $campaign["spend"] ."', '". $campaign["reach"] ."', '". $campaign["impressions"] ."', '". $campaign["date_start"] ."', '". $campaign["date_stop"] ."', '". $campaign["unique_clicks"] ."', '". $campaign["cost_per_inline_link_click"] ."', '". $campaign["ctr"] ."','". $campaign["cpm"] ."', '". $_GET["lpage"] ."', '". $nameArray[0]."-".$nameArray[3] ."', '". str_replace($chars, $replace, trim(strtolower(utf8_decode($nameArray[0]."-".$nameArray[3])))) ."', '". str_replace($chars, $replace, strtolower(utf8_decode($nameArray[2]))) ."', '". $status ."', 'facebook')";

                            $sth = $db->dbh->prepare($sql);
                            $sth->execute();
                   }
}

On initial loading of the dashboard it will run this script with a defalt time range, and it is then possible to select a specific date range on the dashboard, that the user wants to view data from, fx the last 14 days - it will then run this script again.

My worries on the subject is that there are about 20 different dashboards that will show data from 20 different campaigns.

Is the limit per APPID or per user token / IP .. If there are 20 different IPs will it then be 20 x 200 calls = 4000 calls per 60 minutes or is it just 200 calls per token?

I can't seem to figure out a better way to get the insights data on-the-fly.

This is the current information:

https://developers.facebook.com/docs/graph-api/advanced/rate-limiting

You can´t circumvent the limits by using different IPs, that would obviously not allowed and not possible. Afaik there is a limit per App, and the general information earlier was "600 calls per 600 seconds per Token". You should always use the most specific Token, a User Token is better than an App Token because you can have different ones (one per User) in an App - which means, more API calls before you hit the limits.

Afaik the limits are not completely static in general, you should always try to stay below the official numbers - and you should cache results in your database. After all, insights for the past don´t change anyway.

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