问题
This is using the Static Maps API.
I have a web page with 3 img tags, each of which is a call to the static maps API, (NB of course this is not the real api key).
The 3 tags are identical, except the zoom, which is 10, 13 and 16 for the three images.
The API Key is from a project with the Static maps API enabled, and billing configured and enabled.
I have sent perhaps 60 requests in total (this is a brand new development project, so I'm just getting started).
What I'm seeing is that sometimes, all three maps are displayed. At other times one (random from the three) map fails with
403 "The Google Maps API server rejected your request. An internal error was found for this API project."
So if I refresh the page 5 times, ie 15 requests, I get approx 4 failures and 11 successes.
So why is Google Maps randomly rejecting some of the requests with this 403?
回答1:
Are you sure your API key is correct?
From https://developers.google.com/maps/documentation/staticmaps/#Limits :
The Google Static Maps API has the following usage limits:
Without an API key:
1,000 Static Maps requests per IP address per 24 hour period. 50 Static Maps requests per IP address per minute. This means that if you have a single page containing more than 50 maps, the page will exceed this limit.
Additional image requests can be purchased on a per application basis at the rate currently listed in the FAQ. Additional quota is purchased through the API Console and requires the use of an API key.
If a user exceeds these limits, the server will return an HTTP 403 status and display the below image to indicate that the quota has been exceeded:
![]()
Seems like the 50 maps per minute could explain your random 403 errors.
If this isn't the problem, I would file a support ticket with Google Geo support since it's labelled as "an internal error".
回答2:
So if I refresh the page 5 times, ie 15 requests, I get approx 4 failures and 11 successes.
I think your requests exceed the limit in short time. I'm not sure how you display the map, but I recommend you load the map serially.
Ex: using JavaScript with https://github.com/caolan/async
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html,body {
height: 100%;
margin: 0;
padding: 0
}
</style>
<script type="text/javascript" src="async.js"></script>
<script type="text/javascript">
function loadImg(params, callback) {
var url = "http://maps.googleapis.com/maps/api/staticmap?" +
params + "&zoom=1&size=100x100" +
"&sensor=false&key={YOUR_KEY_IS_HERE}";
var img = new Image();
img.src = url;
img.onload = function() {
document.body.appendChild(img);
callback();
};
img.onerror = function() {
callback(url);
}
}
function loadMaps() {
var urlList = [
"markers=label:0|LosAngles",
"markers=label:1|NewYork",
"markers=label:2|SanFrancisco",
"markers=label:3|Frorida",
"markers=label:4|Arizona",
"markers=label:5|Ohaio",
"markers=label:6|Hawai",
"markers=label:7|Texus",
"markers=label:8|Seattle",
"markers=label:9|Florida",
"markers=label:A|kansas",
"markers=label:B|utah",
"markers=label:C|iowa",
"markers=label:D|oregon",
"markers=label:E|alaska",
"markers=label:F|Washington D.C"
];
async.eachSeries(urlList, loadImg, function(err) {
if (err) {
console.log("error", err);
} else {
console.log("all image are loaded");
}
});
}
</script>
</head>
<body onload="loadMaps()">
</body>
</html>
来源:https://stackoverflow.com/questions/21934342/what-causes-the-google-maps-api-server-rejected-your-request-an-internal-error