This IP, site or mobile application is not authorized to use this API key
Asked Answered
S

14

124

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 find 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.

Serviceable answered 21/2, 2014 at 11:30 Comment(4)
you have to get a authorised key from google , and put it into the apiFaille
There is already an API key availableInformal
There is an official document for this issue: chromium.org/Home/chromium-security/…Salpingotomy
Is this api paid or unpaid ?Idolatry
A
153

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.

EDIT

I believe the web URL has changed in the past years. You can access developers console from here now - https://console.developers.google.com/apis/dashboard

  • Navigate to developers console - https://console.developers.google.com/ or use the link from details to navigate directly to API dashboard.
  • Under developer console, find Label from the left navigation panel
  • Select project
  • Choose Credentials from the left Navigation panel
  • You could create credentials type from the Top nav bar as required.

Hope this answer will help you and other viewers. Good Luck .. :)

Aintab answered 16/6, 2014 at 1:30 Comment(15)
Very Important 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.Grimsley
That's correct.. only specify the IP Address/Addresses for testing purpose. Else, leave it blank. Because you are restricting the app or the api key to work only on the specific devices/app.Aintab
What if i leave the ip address blank for testing purpose is that a problem ??Scuffle
@SagarDevanga if we leave the ip address blank and if the implementation you are working based on the Key is incomplete, and anyone who is using the app/web-app that you are working on, can get errors since your app/web-app must be using this key somewhere in you app to get specific features and it will be a bad user experience if a user can't access to that specific feature.Aintab
NOTE: Enter the IP Address only when you want to use it for your testing purpose. Else leave the IP Address section blank. -- I read geocode service key (it is called serverkey, not browserkey) need to be secured and it is not recommended for calling from client (browser). doesnt it makes more sense to restrict to server ip addresses in prod too.Insufficient
@Aintab Thanks for elaborative answer. you can add one more node in your answer. Along with server key, corresponding api should be enabled from the list of apis. because for my case, everything was set as described, but yet weren't getting any data. then eventually turned all the related apis and got the result!Perambulator
@johnshumon Yes i guess.. haven't updated the answer for ages. Might be some new API changes.Aintab
Thanks; It ease my life :)Pforzheim
May want to also make sure Google Places API Web Service is an enabled API as wellVaud
i am confused between API key & Server key &Browser Key please anyone explain.Preiser
I also had to add the IPv6 address, because the server had both v4 & v6 enabledMoth
I was able to use ios app key itself and get it working following Tuan Nguyen answerGoldman
Wrestled with this for hours before discovering that the new "project" must now be linked to a Google cloud billing account in order for the Google API to stop giving these various generic errors. Threshold can be set to $0 so you'll never be charged if usage exceeds the allowed quota.Eakin
There is no such thing as "Server Key" anymore. See my answer below.Catima
You can just "Edit the current server key" at "console.developers.google.com" and DO NOT restrict the key for any specific device. "none". Helped.Megalo
M
20
  1. Choose key
  2. API Restriction tab
  3. Choose API key
  4. Save
  5. Choose Application Restriction -> None
  6. Save

enter image description here

enter image description here

enter image description here

enter image description here

Magnuson answered 21/9, 2018 at 8:3 Comment(5)
i had few services listed in api restrictions but not geocodingOmnipresent
worked like a charm. Thanks was trying to geocoding. I set the app restrictions to none as you pointed out and it worked.Goldman
Restrictions: none is pretty dangerous.Belong
Disabling security is not a solution!Subadar
DO NOT LEAVE API KEY UNRESTRICTED! The new "project" must now be linked to a billing account in order for the Google API to stop giving these various generic errors. Threshold can be set to $0 so you'll never be charged if usage exceeds the allowed quota.Eakin
B
14

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.

Brodeur answered 11/3, 2014 at 21:18 Comment(2)
1+ Will need to create server API key for using Geocode service of Google. Also need to enable Google map geocodding service from Google's API console.. Thanks!!Dynamite
Wrestled with this for hours before discovering that the new "project" must now be linked to a Google cloud billing account in order for the Google API to stop giving these various generic errors. Threshold can be set to $0 so you'll never be charged if usage exceeds the allowed quota.Eakin
D
8

The Google Places API does not currently support Android or iOS keys generated from the Google APIs Console. Only Server and Browser keys are currently supported.

Dupre answered 24/6, 2016 at 9:10 Comment(3)
Interesting... so how does one generate a key for use in Android or iOS apps?Jameejamel
Your Browser keys will work in Android and iOS. Get Browser keys in Google APIs ConsoleDupre
They don't without some extra effort. I just figured this out after a frustrating day yesterday; there's an additional step for apps: https://mcmap.net/q/180142/-this-ip-site-or-mobile-application-is-not-authorized-to-use-this-api-keyJameejamel
C
3

You're trying to use an API KEY which you restricted in a way that won't allow this action.

According to Google:

Note: If you need to call web, web service, and/or mobile APIs from the same (client-side) app, create and restrict multiple keys.

So the right thing to do is to create another API KEY, and choose the correct restrictions for this matter. In your case, choose "IP addresses" (under "Application restrictions"), and use "ADD AN ITEM" to add your server ip. Notice that leaving a blank list won't work, and will result in google changing your restrictions to "None".

Also, don't forget to add the relevant APIs under "API restrictions" (in your case "Geocoding API").

One last thing - Google is blocking the use of this API until you link your app to Google Cloud Billing Account. So if you didn't do it yet, once you successfully get a response, it will say you have to do it first (it has a free starting package).

Catima answered 11/10, 2019 at 13:32 Comment(0)
O
2

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.

Officialdom answered 4/3, 2015 at 5:49 Comment(3)
While this may answer the question it’s always a good idea to put some text in your answer to explain what you're doing. Read how to write a good answer. Also, you should include some code.Hyperbole
Could you please provide a snippetScuffle
Here's what I did, and it worked perfectly: var options = { url: url, headers:{ Referer:'xxx.herokuapp.com' } }; request.get(options, function(...Patino
F
1

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

Fuji answered 26/5, 2014 at 13:23 Comment(2)
could you please elaborateScuffle
While Creating the key you have as place to add Referer Address please Check you had Added something there. if Added Clear itFuji
G
1

Also, the corresponding API should be enabled for the given project

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

Gayle answered 19/11, 2015 at 18:9 Comment(1)
I did add my project name as you pointed, but it is not working.Liaison
A
1

For the latest version of the API the exact opposite seems to be true for me.

When calling the url https://maps.googleapis.com/maps/api/geocode/json?address=<address>&key=<key> I was getting the following error

You must use an API key to authenticate each request to Google Maps Platform APIs. For additional information, please refer to http://g.co/dev/maps-no-account

Once I switched the order to https://maps.googleapis.com/maps/api/geocode/json?key=<key>&address=<address> it worked fine.

Note that the error message received above was the message I got when going directly to the URL in the browser. When I called the API from a software program I received an HTML response with basically the following message:

We're sorry... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.

Arciniega answered 6/2, 2019 at 16:17 Comment(1)
Wrestled with this for hours before discovering that the new "project" must now be linked to a Google cloud billing account in order for the Google API to stop giving these various generic errors. Threshold can be set to $0 so you'll never be charged if usage exceeds the allowed quota.Eakin
J
0

For iOS or Android apps, the key needs an extra privilege granted.

Go to the Google Console -> APIs and Services -> Library. Tap the Places library for your platform and then tap Enable.

See https://developers.google.com/maps/gmp-get-started#enable-api-sdk

Jameejamel answered 27/9, 2019 at 14:21 Comment(0)
T
0

The reason this error is occurring because of the restrictions you have added when you create add the sha1 fingerprint on google cloud console , remove the fingerprints from android or ios then save .(the ip of that mobile phone will no longer be restricted)

Triclinium answered 11/1, 2023 at 12:38 Comment(0)
G
-1

Authentication, quotas, pricing, and policies Authentication To use the Directions API, you must first enable the API and obtain the proper authentication credentials. For more information, see Get Started with Google Maps Platform.

Quotas and pricing Review the usage and billing page for details on the quotas and pricing set for the Directions API.

Policies Use of the Directions API must be in accordance with the API policies.

more know : visit:--- https://developers.google.com/maps/documentation/directions/start?hl=en_US

Galoot answered 19/4, 2020 at 10:37 Comment(0)
A
-3
  url = https://maps.googleapis.com/maps/api/directions/json?origin=19.0176147,72.8561644&destination=28.65381,77.22897&mode=driving&key=AIzaSyATaUNPUjc5rs0lVp2Z_spnJle-AvhKLHY

add only in AppDelegate like

            GMSServices.provideAPIKey("AIzaSyATaUNPUjc5rs0lVp2Z_spnJle-AvhKLHY")

and remove the key in this url.

now url is

https://maps.googleapis.com/maps/api/directions/json?origin=19.0176147,72.8561644&destination=28.65381,77.22897&mode=driving
Adkins answered 21/8, 2018 at 11:43 Comment(0)
S
-4

Disable both direction api and geocoding api and re-enable.

it works for only 5-10 seconds and than automatically disabled itself.

it means you have only 5-10 sec to test you assignment.

Sylvanus answered 17/2, 2020 at 7:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.