Google Geocode API "REQUEST_DENIED" in JSON response - reverse geocode action - google-maps-api-3

Looked everywhere — and have read dozens of other questions regarding Google APIs (Maps, Geocode, Places, Autocomplete, etc) — and nothing has worked.
I have an API key with Places, Static Maps, and Maps v3 & v2 services enabled.
I am trying to perform a reverse geocode (get street address information via JSON from lat/long coords).
Here is the URL I am passing in my JavaScript (last 5 digits of API key replaced with #####:
http://maps.googleapis.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true&key=AIzaSyDbfv8bFidX1hSbXwwKTTxWQYgU7g####
The JSON response is:
{
"results" : [],
"status" : "REQUEST_DENIED"
}
As you can see, there is a "sensor=true" parameter being passed - which is the problem according to the Google Document supporting this API, but that is clearly not the case here.
I also tried passing simply
http://maps.googleapis.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true
which returns expected JSON response when the URL is entered into the addressbar of a browser — but when added to the JavaScript in my HTML file, I again receive:
{
"results" : [],
"status" : "REQUEST_DENIED"
}
Any assistance is welcome, and greatly appreciated.

Google don't particularly want you to use this static API in a web page. You should be using the Maps API in a web page, and its associated geocoding functionality (because you need to show the results on a map anyway). These static APIs are intended for use server-side, so it looks like they now refuse requests which come with an HTTP_REFERER header.
(Using the key server-side allows you to keep track of statistics, but an invalid key will always result in REQUEST_DENIED whether there is a referrer header or not.)

I kept struggling with the exact same problem and I believe I came up with a very practical solution, which actually works just fine with me! You just have to make a small modification to your request query's URI.
Instead of querying the
http://maps.googleapis.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true
you should actually query the google maps api using the following URI:
http://maps.google.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true
That small modification did the work for me like a charm!
Hope this helps.

Related

How to list all parameters available to query via API?

As a end-point user of an API, how can I list all parameters available to pass the query? In my case (stats about Age of Empires 2 matches), the website describing the API has a list with some of them but it seems there are more available.
To provide more context, I'm extracting the following information:
GET("https://aoe2.net/api/matches?game=aoe2de&count=1000&since=1632744000&map_type=12")
but for some reason the last condition, map_type=12 does nothing (output is the same as without it). I'm after the list of parameters available, so I can extract what I want.
PD: this post is closely related but does not focus on API. Perhaps this makes a difference, as the second answer there seems to suggest.
It is not possible to find out all available (undocumented) query parameters for a query, unless the API explicitly provides such a method or you can find out how the API server processes the query.
For instance, if the API server code is open source, you could find out from the code how the query is processed. Provided that you find the code also.
The answers in the post you linked are similarly valid for an API site as well as for one that provides content for a web browser (a web server can be both).
Under the hood, there is not necessarily any difference between an API server or a server that provides web content (html) in terms of how queries are handled.
As for the parameters seemingly without an effect, it seems that the API in question does not validate the query parameters, i.e., you can put arbitrary parameters in the query and the server will simply ignore parameters that it is not specifically programmed to use.
The documentation on their website is all any of us have to go by https://aoe2.net/#api
You can't just add your own parameters to the URL and expect it to return a value back as they have to have coded it to work that way.
Your best bet is to just extract as much data as you can by increasing the count parameter, then loop through the JSON response and extract the map_type from there.
JavaScript example:
<script>
json=[{"match_id":"1953364","lobby_id":null,"game_type":0},
{"match_id":"1961217","lobby_id":null,"game_type":0},
{"match_id":"1962068","lobby_id":null,"game_type":1},
{"match_id":"1962821","lobby_id":null,"game_type":0},
{"match_id":"1963814","lobby_id":null,"game_type":0},
{"match_id":"1963807","lobby_id":null,"game_type":0},
{"match_id":"1963908","lobby_id":null,"game_type":0},
{"match_id":"1963716","lobby_id":null,"game_type":0},
{"match_id":"1964491","lobby_id":null,"game_type":0},
{"match_id":"1964535","lobby_id":null,"game_type":12},];
for(var i = 0; i < json.length; i++) {
var obj = json[i];
if(obj.game_type==12){
//do something with game_type 12 json object
console.log(obj);
}
}
</script>

Getting RefererNotAllowedMapError from GAPI whereas the restriction pattern defined seems to match the referring URL

A.S/ probably for another SE.com site: why "referer" is spelt with only r at Google's?
Anyway, here we go again with another occurrence of RefererNotAllowedMapError.
I couldn't find my answer in the existing Q&As.
Hypothesis:
I have a local website that includes a GMap.
It displays and works
fine provided I remove all restrictions on that key, from the Google
API console.
But the browser will receive a Google Maps JavaScript
API error: RefererNotAllowedMapError whenever I add a referrer
restriction, which seems to match the refering URL.
The referrer, where the map is being called form, is:
https://app.developr.online.local/projects?p=name-asc-0-20-1&a=createProject
Below is my GAPI KEY security configuration:
Below is the corresponding console output:
To be noted:
If I add a trailing asterisk when declaring the referer, validating that entry will clear it anyway. To me it means: "that's ok, we're covering trailing /* already.".
My question: what pattern should I enter as a referrer (2 r's) to have it recognised by GAPI security layer?
I've tried a few things, I didn't get a cigar.
Thank you.

Why does the Google Analytics API method return less data than web ui

Do the Google Analytics API methods allow to get the same amount of data, that is accessible through the web UI?
The problem is, for example, that in browser I can see more that 3000 lines in a report, but the API method returs only several hundreds.
Here is a URL for API method that I use:
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A73XXXXXX&dimensions=ga%3ApagePath%2Cga%3Akeyword&metrics=ga%3Avisits%2Cga%3AvisitBounceRate&sort=-ga%3Avisits&start-date=2015-09-01&end-date=2015-09-30&start-index=1&max-results=3000
The API method you are using has queries appended on it. (Everything after the '?' and seperated by the '&') These are not part of the URL but actually information that is used by the server to customize your result. By changing the URL to say: https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A73XXXXXX&dimensions=ga%3ApagePath%2Cga%3Akeyword&metrics=ga%3Avisits%2Cga%3AvisitBounceRate&sort=-ga%3Avisits&start-date=2015-09-01&end-date=2015-09-30&start-index=1&max-results=10000 , you should get more results in your response. You may also want to change the start and end date, just make sure to keep the YYYY-MM-DD format.

#, [, and ] in a URL query string for partial API call

I'm looking doing partial requests from the Google Picasa API. They show this as an exmaple:
GET https://picasaweb.google.com/data/feed/api/user/photosapi?kind=album&v=2.0&fields=entry(title,gphoto:numphotos,media:group(media:thumbnail),link[#rel='http://schemas.google.com/g/2005#feed'](#href))
I understand this has to be URL encoded before it's used, but how does the server interpret symbols like #, [, and ]?
Since this API call will be requesting an XML file, do these characters help the browser navigate the XML to get the requested information (since this is partial request of the album information, not a full dump of the user's photo data)?
I found the answer. This is the syntax for Google's Partial Response API calls.
More info here: http://code.google.com/labs/faq.html#experimental

Is it possible to use a search string url with Google Calendar

Would any body know if it is possible to search calendar events with a url string?
For example with gMail you could use:
https://mail.google.com/mail/?shva=1#search/Search+Term
to search for the words 'search' and 'term'
Any help or advice greatly appreciated.
Cheers
Noel
This is how you can search Google Calendar using a query parameter in the url:
https://www.google.com/calendar/render?q=TERM
where TERM is the string you're searching for.
So, you can search using a GET request.
Using Chrome's dev tools, it appears as though Google Calendar searches are performed using a POST request, so you won't be able to pass search terms into urls to fetch a response (which would be a GET request).
Update: Looks like a GET request will still return results, but the response is some form of JSON.
Here is the url (I x'd out my specific info), looks like its not meant for what you want to use it for:
https://www.google.com/calendar/search?ctz=America/New_York&hl=en&as_tp=basic&as_myuids=xxx&as_otheruids=xxx&as_q=kai%20mallea&as_cal=xxx;xxx&secid=xxx
A generalization of the current answer is:
https://calendar.google.com/calendar/b/0/render?q=TERM
where 0 is the index of the desired Google account (if you have multiple accounts).

Resources