Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding "User request limit reached" #30

Closed
arass opened this issue Jun 18, 2016 · 13 comments
Closed

Avoiding "User request limit reached" #30

arass opened this issue Jun 18, 2016 · 13 comments

Comments

@arass
Copy link

arass commented Jun 18, 2016

I haven't ran a wireshark (too lazy), but I seem to be running into the issue with 200 requests per hour max over an account with only 25 ads.

I have code that looks like this:
APINodeList ads = adAccount.getAds()..[blah blah blah]..execute() (1 call, returns 25 ads)
Then I go through all ads, requesting insights:
for (Ad ad : ads) {
APINodeList adInsights = ad.getInsights().[blah].execute() (should get called 25 times)
methodThatExaminesInsights(each adInsight)
}

Now considering there should be only 26 calls to go to backend, I getthe 200-max error after going through 180 or so insights. Which means that looking at an insight generates a call?

This seems silly as that means there is no way to examine even a single account's insights

Seems like a bug.

Any help would be appreciated.

@arass
Copy link
Author

arass commented Jun 19, 2016

Was looking more into it. It seems that the cause is that even though I'm only making a few calls (<25) - the "cost" of these calls combined is higher than allowed?

So FB built an API that's useless to access Insights?

I can create a server/proxy farm that would cycle IPs, but was hoping someone had a better solution.
We can't wait hours to load a few stats on ads.
Seems like an epic fail on the part of FB.
Any suggestions?

@JiamingFB
Copy link
Contributor

Hi arass,

Looks like you've got throttled for making too many api calls within short time. If you make tens of API calls within a few seconds, that could happen.

Suggested solution:

  1. Use AdAccount/Campaign/AdSet level insights and set 'level' to 'ad', so that you can get the insights of all ads in one HTTP request, instead of making one api call for each of the ads.
  2. Apply for higher access tier if eligible. This will increase your rate limit. You can see more details on https://developers.facebook.com/docs/marketing-api/access.

@arass
Copy link
Author

arass commented Jun 22, 2016

Tried going through adsets before, but got killed on too many requests there also.

Went to the batch mode, for now, while we test (at least gets me a full set of insights). But your solution2 seems like the ultimate answer and is worth perusing. Thanks a lot! This makes more sense than encountering such a tiny rate limit and trying to work with it.

Much appreciated!

@arass arass closed this as completed Jun 22, 2016
@priyachetwani
Copy link

Hi arass,

Looks like you've got throttled for making too many api calls within short time. If you make tens of API calls within a few seconds, that could happen.

Suggested solution:

  1. Use AdAccount/Campaign/AdSet level insights and set 'level' to 'ad', so that you can get the insights of all ads in one HTTP request, instead of making one api call for each of the ads.
  2. Apply for higher access tier if eligible. This will increase your rate limit. You can see more details on https://developers.facebook.com/docs/marketing-api/access.

Yes he is right. accessing edges like adsets and ads directly from Ad_accounts node is better than accessing them individually . It would require less api requests.

@priyachetwani
Copy link

Accessing edges like adsets and ads directly from Ad_accounts node is better than accessing them individually . It would require less api requests.

@arass
Copy link
Author

arass commented Nov 17, 2018 via email

@leopragi
Copy link

leopragi commented Apr 19, 2021

Just adding:

You can use expand fields

https://graph.facebook.com/v9.0/<ACCOUNT_ID>/ads?fields=name,account_id,id,insights.date_preset(yesterday){reach,impressions,clicks,cpc,cpm,cpp,ctr}

or

Insights api with account node with level

https://graph.facebook.com/v9.0/<ACCOUNT_ID>/insights?date_preset=yesterday&level=ad

This looks like a neat approach to me. I welcome suggestions!

@mohitg8a
Copy link

How can I pass insights time_range? I have tried to pass this parameter but it does not work.

@edt-andrew
Copy link

edt-andrew commented Aug 12, 2021

How can I pass insights time_range? I have tried to pass this parameter but it does not work.

in json:
params = {other params,
'time_range': '{"since":"yyyy-mm-dd","until":"yyyy-mm-dd"}'
}

url param:

&time_range={"since":"yyyy-mm-dd","until":"yyyy-mm-dd"}

@mohitg8a
Copy link

mohitg8a commented Aug 13, 2021

Hello Andrew,

I want to pass multiple params, I have tried like this: insights(time_range={"since":"2021-07-14","until":"2021-07-14"},action_attribution_windows=['1d_click','1d_view','7d_view','7d_click']) but it's not work.

I am only able to pass one params at a time like this: insights.time_range({"since":"2021-07-14","until":"2021-07-14"}){reach,impressions,clicks,cpc,cpm,cpp,ctr}

Can you please help me with how can I pass multiple params?

I want to pass time_range and action_attribution_windows.

Thanks!

@galacticgumshoe
Copy link

@mohitg8a Not sure posting a question unrelated to the closed issue is the right place for your answers. For insights, consider using the inner classes on the top-level class representing the level of insights you want to fetch (Campaign, AdAccount, etc). Those inner classes all say APIRequestGetInsights or APIRequestGetInsightsAsync. Pick whether you want to do a synchronous or asynchronous call. In my case, I need insights at the Ad Account level, so I use AdAccount.APIRequestGetInsights. If you look at those classes you'll see a bunch of setters which allow you to pass all of your various parameters before you call the .execute() on the sync class or the AdReportRun class for the async call. I initiate my own custom value object facebookAdsInsightsRequest (this is just a POJO I wrote that has all of the values in fields with getters/setters on them):

        FacebookAdsInsightsRequest facebookAdsInsightsRequest = new FacebookAdsInsightsRequest();
        facebookAdsInsightsRequest.setTimeRangeFormatted(startDate, endDate);
        facebookAdsInsightsRequest.set...

Then I can pass these fields into each of the setters on the APIRequestGetInsights class (this example is used to get all the campaigns that have some activity within the start and end date range for a given Ad Account):

        AdAccount.APIRequestGetInsights activeCampaigns = new AdAccount.APIRequestGetInsights(adAccountId, context);
        APINodeList<AdsInsights> adsInsights;
        try {
            activeCampaigns.setParam("level", facebookAdsInsightsRequest.getLevel())
                    .setParam("time_range", facebookAdsInsightsRequest.getTimeRangeFormatted())
                    .setParam("time_increment", facebookAdsInsightsRequest.getTimeIncrement())
                    .setParam("filtering", "[" + facebookAdsInsightsRequest.getCampaignFilterJson() + "]")
            activeCampaigns.setFields("campaign_id");
            adsInsights = activeCampaigns.execute().withAutoPaginationIterator(true);

            List<String> innerCount = new ArrayList<>();
            for (AdsInsights adsInsight : adsInsights) {
                String campaignId = adsInsight.getFieldCampaignId();
                if (campaignId != null) {
                    campaignIds.add(campaignId);
                    log.debug("Campaign ID {} has activity!", campaignId);
                    innerCount.add(campaignId);
                }
            }
        } catch (APIException e) { 
                    //do something with your exception here
        }

@mohitg8a
Copy link

Thanks, it's really helpful for me.

Thank you again.

@mohitg8a
Copy link

Hello Guys,

how can have a similar ad creative showing that they are being used in multiple ads?

We are building an internal reporting system for creative ads reporting. And we would like to know how can have the similar ad creative showing that they are being used in multiple ads similar to what FB does: https://prnt.sc/1qh0ezk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants