Google Geolocation API: 403 POST Forbidden error

1.3k views Asked by At

I'm using Google's geolocation api, but getting this error:

"POST http://www.googleapis.com/geolocation/v1/geolocate?key= //my API key... 403 (Forbidden)"

This is a brand new API key, so I can't imagine I'm hitting my daily limit...

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

There are 1 answers

0
Nick Tamburro On BEST ANSWER

Google's geolocation API requires https rather than http.

So code from above is corrected by just adding an 's' to line 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);
   }