How to handle Google Ads API rate limit when calling REST API? - google-ads-api

I am using Google Ads REST API to pull Ads data. I am not using client library.
One question, how do you programatically check current API usage when calling requests, so you can stop and wait before continuing? Other APIs like Facebook Marketing API has a header in the result that tells you how much requests you have left, so I could stop and wait. Is there a similar info on Google Ads REST API?
Thank you for reading this.

I've seen nothing in the documentation so far to suggest that there is :(
(There is, separately, a RateExceeded error, which includes a retryAfterSeconds field, if you're going too fast / the API is overloaded.)

Ultimately, I tried this method. So far, I haven't reached limit with it:
The basic developer token for Google Ads API allow 15,000 requests per day as of this answer (Link: https://developers.google.com/google-ads/api/docs/access-levels). So that's 15,000 / 24 = 625 requests every hours.
Further divisions show that I can have 625/60 = 10.4 requests every minutes. So 1 request every 6 seconds will ensure I won't reach rate limit.
So my solution is:
Measure the time it takes to complete a request call and subsequent processing
If total time is over 6 seconds, perform the next request. Else, wait so the total time is 6 seconds, then perform the next request.
The below code is what I used to perform this. Hope it helps you guys.
import time
from math import ceil
waiting_seconds = 6
start_time = time.time()
###############PERFORM API REQUEST HERE
#Measure how long it takes, should be at least 6 secs to be under API limit
end_time = time.time()
elapsed = end_time - start_time
if elapsed < waiting_seconds:
remaining = ceil(waiting_seconds - elapsed)
time.sleep(remaining)

Related

Twilio Studio - Send and Wait for Reply - Multiple

I am trying to define a period of time (lets say 10 minutes, that stores all responses after a certain widget), and then save all those replies into one variable. Is this possible to do with twilio studio?
Example:
BOT: [sends message]
//start time - 0 min
USER: [reply1]
USER: [reply2]
USER: [reply3]
//end time - 10 min
finalString = reply1+reply2+reply3...reply i
Then I'd like to send that via HTTP POST request (This part seems to be easy if the values are all stored). But I'd want the HTTP request to execute after the 10 minutes, if there is at least one reply.
Any Twilio Evangelists that could help me out?
The Twilio Send & Wait For Reply widget has a parameter called "Stop Gathering After", which waits X number of seconds for a response, before heading down the No Reply path. The parameter does not accept liquid syntax, so it is isn't possible to subtract the remaining time from your 10 minute budget (should you receive a response to the first widget say 3 minutes in), to ensure all the currently captured responses are sent to your server for that 10 minute maximum collection time.
Twilio developer evangelist here.
That's not something Studio is set up to do. It is intended for back and forth conversation, not a waiting period.
If you want to store something up like this, you will need to build the solution yourself.

Log data into grafana for every minute

The below code registers five metrics count, oneminuteRate, fiftenMinuteRate, fiveMinuteRate, meanRate into graphite for every 30 seconds from my application.
public void collectMetric(string metricName, long metricValue){
mr.meter(metricName).mark(value)
}
I would like to show in the Grafana dashboard the no of requests that are received every minute.(i,e if in the first minute 60 is received, in the second minute 120 is received) Since the count in the meter metric above just keeps increasing and all the *Rate values are events per second. I am not sure how to log metric into Grafana dashboard that displays the no of requests received per minute. Any advice is highly appreciated?
Suppose if I use
mr.counter(metricName).inc(value) IS there a way to reset the counters every 1 minute?
I had the same problem. The way that I found is that I resolved this in Grafana.
When you're on the panel's metrics, you can add a function to your query like this:
You can try the derivative() function or perSecond() function but these functions are not completly reliable, it depends what you're doing with these in your panel.
But with these you'll see the number of input in time and not the total.

How does Google Analytics calculate requests/hits frequency?

I want to use Google Analytics to track my iOS application hits.
I've read Google Analytics Collection Limits and Quotas article. It says
Each property starts with 60 hits that are replenished at a rate of 1 hit every 2 seconds. Applies to All hits except for ecommerce (item or transaction)
It is not quite clear for me what "1 hit every 2 seconds" means.
Here is what i think:
1 hit every 2 seconds = 0.5 hits per second
frequency (hits per second) = number of hits / time interval (seconds)
So my question is:
What time interval does Google Analytics use to calculate hits frequency?
Is it time elapsed from session start? Or is it a time for current day? Or is it calculated every 2 seconds?
I believe this rate limiting happens on the client (via the SDK) and not on the server. Server side limits exist, but they apply equally to all clients (so not iOS-specific).
The 60 hits + 1 per 2 seconds rule means that when you instantiate the tracker object in your app, it starts out with a 60 hit quota, and it adds 1 additional hit every 2 seconds.
As an example, if you instantiated the tracker, and the user didn't do anything for 10 seconds, you'd have 65 hits left in your quota. If the user then performed 10 actions within the next 10 seconds, you'd be back to 60 hits left in your quota. Does that make sense?
So to answer your ultimate question, the it's not about time interval, it's about when the clock starts, and that happens when the tracker object is created on the client.

Rate Limit Twitter API

I'm kind of confusion with twitter api guide on rate limiting mention over here https://dev.twitter.com/docs/rate-limiting/1.1
In their guide twitter has mention the follow field would be present in the response headers which can be use to a determine the amount of api call allowed , left and will rest at info
X-Rate-Limit-Limit: the rate limit ceiling for that given request
X-Rate-Limit-Remaining: the number of requests left for the 15 minute window
X-Rate-Limit-Reset: the remaining window before the rate limit resets in UTC epoch seconds
Now they have also given a rate limit status api to query against
https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status
Now I'm kind of confuse which of the above value should I follow to see how much api call is available for me before the desired limit is reach .
Both seem to return the same. While /get/application/rate_limit_status is an API call which returns rate limits for all resources, X-rate-limits sets the header for the resource you just called.
Use /get/application/rate_limit_status to cache the no of API calls remaining, refresh at periodic intervals rather than having to make a call and then parse the header info to check if you've exceeded rate limits

PRAW: inconsistent behavior when trying to monitor ups/downs

I am trying to monitor a post, and plot the number of ups and downs over a 24 hour period (at 5 minute intervals). The core of the code looks like this:
while True:
post = r.get_submission(submission_id='23a1zz')
time.sleep(5)
post.refresh()
print post.ups
time.sleep(5*60)
However, it does not reflect the true ups and downs. It's stuck at the same number even though the actual post is pretty dynamic.
The API Guidelines state that the same resource shouldn't be requested more often than every 30 seconds. This guideline is backed by a cache, on both Reddit and PRAW's end that will return the same content if requested again within a short while. http://praw.readthedocs.org/en/latest/pages/faq.html#i-made-a-change-but-it-doesn-t-seem-to-have-an-effect

Resources