簡體   English   中英

Google Geolocation API:403 POST禁止錯誤

[英]Google Geolocation API: 403 POST Forbidden error

我正在使用Google的地理位置API,但收到此錯誤:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM