Reputation: 1339
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:
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.
Upvotes: 132
Views: 186173
Reputation: 7553
I have encountered this error even if I have not restricted my keys with IP restrictions.
{
"error_message": "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 104.X.2X.XX7, with empty referer",
"predictions": [],
"status": "REQUEST_DENIED"
}
To fix this try out the below solutions
Open the Google Cloud Console. and go to the APIs and Creditionals
There are two main types of restrictions:
1. iOS & Android Restrictions
For Android:
Ensure the package name and SHA-1 certificate fingerprint are correctly set.
For iOS:
Ensure the bundle ID is correct.
Steps to Verify:
Check the Bundle ID: Verify that the bundle ID used in your app matches the one specified in the Cloud Console.
Check the SHA-1 Certificate: For development, use the SHA-1 from your keystore. For production apps available on the Play Store, obtain the SHA-1 from the Play Console.
To get the SHA-1 for production apps:
Go to the Google Play Console.
Navigate to your app.
Go to Setup -> App Signing.
Use the SHA-1 from the Upload key certificate section.
2. API Restrictions (Enabled APIs)
If API restrictions are enabled, ensure that all required APIs are enabled. Depending on your use case, you might need to enable APIs such as:
Maps SDK for Android, Geocoding API, Maps SDK for iOS, Places API, Geolocation API.
When making API requests, ensure that the required details are included in the headers.
For iOS:
headers: {
'X-IOS-Bundle-Identifier': 'com.example.yourapp'
}
For Android:
headers: {
'X-Android-Package': 'com.example.yourapp',
'X-Android-Cert': 'G0KOJCWECG459050J69AL7I37BS3H5O1E1840747' // Ensure to use the SHA-1 without colons
}
Note : In my case I was using SHA-1 with colons (eg.G0:KO:JC:WE:CG:45:90:50:J6:9A:L7:I3:7B:S3:H5:O1:E1:84:07:47)
Removing colons from SHA-1 Fixed my issue
Upvotes: 2
Reputation: 21
Check your Google APIs Console, If you set Application Restriction to iOS apps,then your api request should set header, code like this:
request.setValue("your-bundle-id", forHTTPHeaderField: "x-ios-bundle-identifier")
Upvotes: 2
Reputation: 9277
Also, the corresponding API should be enabled for the given project
https://console.developers.google.com/apis/library?project=projectnamehere
Upvotes: 1
Reputation: 1
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)
Upvotes: -1
Reputation: 5425
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:
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:
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
Hope this answer will help you and other viewers. Good Luck .. :)
Upvotes: 157
Reputation: 1385
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).
Upvotes: 3
Reputation: 23398
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
Upvotes: 0
Reputation: 453
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.
Upvotes: 1
Reputation: 2607
Upvotes: 21
Reputation: 13
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
Upvotes: -3
Reputation: 768
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.
Upvotes: 8
Reputation: 1763
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.
Upvotes: 3
Reputation: 92
You create an key with out referer dont enter the referer address
Upvotes: 1
Reputation: 5041
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.
Upvotes: 14