2017-09-02 82 views
0

我使用谷歌的地理位置API,但得到这个错误:谷歌地理位置API:403 POST禁止错误

“POST http://www.googleapis.com/geolocation/v1/geolocate?key= //我的API密钥... 403(禁止)”

这是一个全新的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); 
     } 
+0

谷歌只允许GET请求,因为据我所知(或至少他们的云API)...尝试发送GET中的信息。或阅读文档。 –

+0

地理位置希望它成为POST。它看起来像我的问题的一部分是该网址需要https而不是http! –

+0

好吧,它帮助你,将其作为自己的答案张贴并接受它。它可能会在未来帮助其他人。 –

回答

0

谷歌的地理位置API需要https,而不是http。

所以从上面的代码只需添加一个“s”更正为第3行:

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); 
    }