Google API Key hits max request limit despite bill

2019-05-23 08:24发布

问题:

I believe I have done everything to properly setup access to the Distance Matrix API.

First, I created a project and a billing account. That billing account is enabled on this project.

Next, I enabled the Distance Matrix API and created an unrestricted (for now) API key.

This is how I am making calls to the Google Distance Matrix API:

var requestUri = string.Format("https://maps.googleapis.com/maps/api/distancematrix/xml?units=imperial&mode=driving&origins={0}&destinations={1}&KEY={2}", originAddress, destinationAddress, apiKey);
var request = WebRequest.Create(requestUri);
var response = request.GetResponse();
return XDocument.Load(response.GetResponseStream());

The XDocument that is returned from this method is then parsed and the distance I am requesting to be calculated is extracted.

However, after 2500 requests, I am receiving an OVER_QUERY_LIMIT with this message:

You have exceeded your daily request quota for this API. We recommend registering for a key at the Google Developers Console: https://console.developers.google.com/apis/credentials?project=_

Have I overlooked any steps in setting up the API key or project/billing account? Or can anybody see something I am doing wrong in my code?

回答1:

KEY= needs to be lowercase key=

var requestUri = string.Format("https://maps.googleapis.com/maps/api/distancematrix/xml?units=imperial&mode=driving&origins={0}
                                &destinations={1}&KEY={2}", originAddress, destinationAddress, apiKey);

should be:

var requestUri = string.Format("https://maps.googleapis.com/maps/api/distancematrix/xml?units=imperial&mode=driving&origins={0}
                                &destinations={1}&key={2}", originAddress, destinationAddress, apiKey);