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

How to get 'X-FB-Ads-Insights-Throttle' header from response? #48

Closed
joaquincorrales opened this issue Jul 9, 2018 · 8 comments
Closed
Labels

Comments

@joaquincorrales
Copy link

Trying to create a scheduled job to fetch insights from customer ad accounts but I need to constantly check the 'X-FB-Ads-Insights-Throttle' header in order to make sure Facebook doesn't limit me.

How can I check this header when calling the insights calls using the library?

@joephayes
Copy link

Check the last_api_response of the ad object you are using. You can access the headers from there. See #50 (comment) for an example.

@joaquincorrales
Copy link
Author

Joe thanks a lot. I'm also trying to handle an ad account being limited or app being limited and catching it with a begin -> rescue but the last_api_response can't be found in the rescue. Maybe I should just make sure it never happens as opposed to trying to handle when it does

@joaquincorrales
Copy link
Author

I'm already performing some sort of "ping" to the ad account before performing anything so I might be good but you can never be too safe.

There's always the scenario that when you ping the adaccount everything is fine but halfway through processing they reach their limit you know

@joephayes
Copy link

joephayes commented Jul 18, 2018

This allows access to the headers of the request that caused the error:

begin
  ad_account = FacebookAds::AdAccount.get("act_#{ad_account_id}", 'name')

  puts "Ad Account Name: #{ad_account.name}"
rescue FacebookAds::APIError => e
  puts e.instance_variable_get(:@api_response).headers
end

produces this:

{"access-control-allow-origin"=>"*", "strict-transport-security"=>"max-age=15552000; preload", "x-fb-trace-id"=>"XXXXXX", "content-type"=>"application/json; charset=UTF-8", "x-fb-rev"=>"4116048", "x-app-usage"=>"{\"call_count\":0,\"total_cputime\":0,\"total_time\":0}", "cache-control"=>"no-store", "pragma"=>"no-cache", "expires"=>"Sat, 01 Jan 2000 00:00:00 GMT", "www-authenticate"=>"OAuth \"Facebook Platform\" \"invalid_token\" \"Invalid OAuth access token.\"", "x-fb-debug"=>"XXXXX", "date"=>"Wed, 18 Jul 2018 22:22:19 GMT", "connection"=>"close", "content-length"=>"113"}

@joaquincorrales
Copy link
Author

That helps tremendously thank you so much Joe!

One last question. Do you know if there's an option to not allow users to edit campaigns made through the API in their ads managers? Or is that impossible.

@joephayes
Copy link

You are welcome! Unfortunately, I don't know if there is a way to block users from editing API created campaigns with Ads Manager. Sorry!

@stale
Copy link

stale bot commented Jan 14, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Jan 14, 2020
@stale
Copy link

stale bot commented Jan 21, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants