I am using https://maps.googleapis.com/maps/api/geocode/json? link with server key and user ip to find the latitude and longitude of any address , when i m trying i am finding the error as
I have a server access key from google and I have put my server's IP address in the their white list.
The URL that I am trying to access via PHP CURL is:
The result that I am getting:
Array ([error_message] => This IP, site or mobile application is not authorized to use this API key. [results] => Array ( ) [status] => REQUEST_DENIED)
Is there anything that I need to configure. The geocoding api is also switched on.
I faced the problem because i did not enable the APL key in Google console.
You create an key with out referer dont enter the referer address
I had the same issue and I found this.
On the url, it requires the server key in the end and not the api key for the app.
So Basically, you just add the server key in the end of the URL like this:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=yourlatitude,yourlongitude&radius=5000&sensor=true&key=SERVERKEY
Now, to obtain the server key, just follow these steps:
1) Go to Developer Console https://code.google.com/apis/console/
2) In the Credentials, under Public API Access , Create New key
3) Select the server key from the option.
4) Enter your IP Address on the field and if you have more ip addresses, you can just add on every single line.NOTE: Enter the IP Address only when you want to use it for your testing purpose. Else leave the IP Address section blank.
5) Once you are done, click create and your new Server Key will be generated and you can then add that server key to your URL.
Last thing is that, instead of putting the sensor=true in the middle of the URL, you can add it in the end like this:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=yourlatitude,yourlongitude&radius=5000&key=SERVERKEY&sensor=true
This will definitely solve the issue and just remember to use the server key for
Places API
.Hope this answer will help you and other viewers. Good Luck .. :)
Google Place API requires the referer HTTP header to be included when making the API call.
Include HTTP header "Referer:yourdomain.com" and this should fix the response issues.
In addition to the API key that is assigned to you, Google also verifies the source of the incoming request by looking at either the
REFERRER
or the IP address. To run an example in curl, create a newServer Key
in Google APIs console. While creating it, you must provide the IP address of the server. In this case, it will be your local IP address. Once you have created aServer Key
and whitelisted your IP address, you should be able to use the new API key in curl.My guess is you probably created your API key as a
Browser Key
which does not require you to whitelist your IP address, but instead uses theREFERRER
HTTP header tag for validation. curl doesn't send this tag by default, so Google was failing to validate your request.Also the corresponding API should be enabled for the given project
https://console.developers.google.com/apis/library?project=projectnamehere