Google 地理位置 API: 403 POST 禁止错误
Google Geolocation API: 403 POST Forbidden error
我正在使用 Google 的地理定位 api,但出现此错误:
"POST http://www.googleapis.com/geolocation/v1/geolocate?key= //my API key... 403 (Forbidden)"
这是一个全新的 API 密钥,所以我无法想象我正在达到我的每日限额...
function GeoLocate() {
var QueryURL =
"http://www.googleapis.com/geolocation/v1/geolocate?key=" +
GeolocationAPIKey;
return new Promise(function(resolve, reject) {
$.ajax({
method: "POST",
url: QueryURL,
}).done(function(response) {
resolve(response);
}).fail(function(err) {
reject(err);
})
})
console.log(response);
}
Google 的地理位置 API 需要 https 而不是 http。
因此,只需在第 3 行添加 's' 即可更正上面的代码:
function GeoLocate() {
var QueryURL =
"https://www.googleapis.com/geolocation/v1/geolocate?key=" +
GeolocationAPIKey;
return new Promise(function(resolve, reject) {
$.ajax({
method: "POST",
url: QueryURL,
}).done(function(response) {
resolve(response);
}).fail(function(err) {
reject(err);
})
})
console.log(response);
}
我正在使用 Google 的地理定位 api,但出现此错误:
"POST http://www.googleapis.com/geolocation/v1/geolocate?key= //my API key... 403 (Forbidden)"
这是一个全新的 API 密钥,所以我无法想象我正在达到我的每日限额...
function GeoLocate() {
var QueryURL =
"http://www.googleapis.com/geolocation/v1/geolocate?key=" +
GeolocationAPIKey;
return new Promise(function(resolve, reject) {
$.ajax({
method: "POST",
url: QueryURL,
}).done(function(response) {
resolve(response);
}).fail(function(err) {
reject(err);
})
})
console.log(response);
}
Google 的地理位置 API 需要 https 而不是 http。
因此,只需在第 3 行添加 's' 即可更正上面的代码:
function GeoLocate() {
var QueryURL =
"https://www.googleapis.com/geolocation/v1/geolocate?key=" +
GeolocationAPIKey;
return new Promise(function(resolve, reject) {
$.ajax({
method: "POST",
url: QueryURL,
}).done(function(response) {
resolve(response);
}).fail(function(err) {
reject(err);
})
})
console.log(response);
}