This IP, site or mobile application is not authori

2019-01-02 17:52发布

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:

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true&key=XXXXXXXXXXXX

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.

9条回答
荒废的爱情
2楼-- · 2019-01-02 18:23

I faced the problem because i did not enable the APL key in Google console.

查看更多
永恒的永恒
3楼-- · 2019-01-02 18:28

You create an key with out referer dont enter the referer address

查看更多
像晚风撩人
4楼-- · 2019-01-02 18:33

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 .. :)

查看更多
还给你的自由
5楼-- · 2019-01-02 18:33

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.

查看更多
几人难应
6楼-- · 2019-01-02 18:34

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 new Server 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 a Server 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 the REFERRER HTTP header tag for validation. curl doesn't send this tag by default, so Google was failing to validate your request.

查看更多
浅入江南
7楼-- · 2019-01-02 18:37

Also the corresponding API should be enabled for the given project

https://console.developers.google.com/apis/library?project=projectnamehere

查看更多
登录 后发表回答