2017-09-02 51 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); 
    }