my apologies - the problem was a coding mistake elsewhere. Please ignore the above.
On 8 November 2017 at 14:18, Ezekiel.incorrigible <[email protected] > wrote: > I am writing a custom function for google sheets which calls on the google > distance matrix api. The function splits up the input data (postcodes) into > blocks of 10 x 10 or less (so that there are 100 or less elements requested > at a time and makes each api request after waiting one second. The function > behaves as desired, returning the correct results for the first request but > returns an error message "You have exceeded your rate-limit for this > API." for the second request. What rate-limit am I exceeding? The standard > limits given on the developer site (https://developers.google. > com/maps/documentation/distance-matrix/usage-limits) are > > - 2,500 free elements per day, calculated as the sum of client-side > > <https://developers.google.com/maps/documentation/javascript/distancematrix> > and > server-side queries. > - Maximum of 25 origins or 25 destinations per request. > - 100 elements per request. > - 100 elements per second, calculated as the sum of client-side > > <https://developers.google.com/maps/documentation/javascript/distancematrix> > and > server-side queries. > > > This error message comes up, even if I delay the second request by 10 > seconds. > > Here is the code that calls the api: > > // send each api request and collect the results in responses[] > var responses = [] > for (var b = 0; b < numofblocks; ++b) { > responses.push(distancematrixrequest(postcodes1blocks[b], postcodes2, > timestamp)); > Utilities.sleep(10000); > } > > function distancematrixrequest(origins, destinations, timestamp) { > origins = origins.join('|'); > destinations = destinations.join('|'); > console.log('api request origins: ' + origins); > console.log('api request destinations: ' + destinations); > var url = "https://maps.googleapis.com/maps/api/distancematrix/json? > units=imperial" > + "&origins=" + encodeURIComponent(origins) + "&destinations=" + > encodeURIComponent(destinations) > + "&mode=transit" + "&departure_time=" + encodeURIComponent(timestamp) > + "&key=AIzaSyDFALppTJkK8f7OZq7ctnSbfgZn4x7DHjQ"; > console.log(url); > var response = JSON.parse(UrlFetchApp.fetch(url)); > console.log(response); > return response; > } > > double-checking the logs confirms that the first request has 10 origins > and 10 destinations and the second has less than 10 origins and 10 > destinations. So what is going wrong? How can I make this work? > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Google Spreadsheets API" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/google-spreadsheets-api/tZbKLBVKwXY/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google Spreadsheets API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
