Google Places API request denied for Android autocomplete, even with the right api key
Asked Answered
M

9

24

I'm trying to make an Autocomplete field which should fetch cities as the user types, by using the Google Places API as described in this tutorial: https://developers.google.com/places/training/autocomplete-android

You've probably found this question around many times before as I did, but none of the answers helped me. Here are the things you should know:

The URL is https://maps.googleapis.com/maps/api/place/autocomplete/json?sensor=false&key=myKey&components=country:ro&input=whatTheUserTypes

Please don't reply by saying you replaced the API key with your own and it worked - the API key which goes there must be Android specific and won't work from a browser.

So did I make the Android API key using the SHA1 fingerprint obtained from the keystore I signed the app with. I turned on Maps and Places APIs from the console. The quota isn't exceeded.

All those and it still gives me REQUEST_DENIED

What I didn't mention is that I have O2Auth activated - does that change anything? Shouldn't it be as simple as putting the API key in the app?

Thanks!

Malapropism answered 1/2, 2013 at 20:49 Comment(0)
M
28

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.

If you would like to request this support, please file a Places API - Feature Request.

Mileage answered 7/2, 2013 at 5:51 Comment(4)
Thanks again, that shed a lot of light on this issue Was it mentioned somewhere in the documentation? It says there in the Autocomplete tutorial, that the API key 'should' be stored on a proxy server, but that leaves many of us to think we can just use it directly from the app anyway.Malapropism
It isn't mentioned in the Places API documentation, however it is mentioned in the APIs console help: "Note that Android keys are only supported by some APIs".Mileage
and what if I want just test it from my webbrowser, there is no chance to work?Parchment
Hi,I have same the problem, In my app need to show search places in AutocompleteView but it give "request denied". please see my question " #20017594". how do you solved?. please help me.Garretson
S
95

Although this has been answered, I think the community could do better.

I was tearing my hair out about this, it just didn't make sense to me.. I was making an iOS/Android App, so I made an iOS/Android Key... Wrong.

With Google's Places API, your bundle identifier isn't even considered.

What you really want to do is this: (I'm using the new User Interface)

1. Log into https://cloud.google.com/console#/project

Select your Project Name, then go into API's & Auth > APIs

Make sure you have Places API Turned on. This is the only thing that needs to be turned on for Places-API to work. enter image description here

2. Go into Credentials

Click CREATE NEW KEY under Public API Access enter image description here

3. Select BROWSER KEY enter image description here

4. Click Create, Nothing Else

Leave the HTTP Refer box empty.

enter image description here

5. Use the Key Generated here

This key will allow ANY user from any device access to the API via your Developer login. You can try it out here: (Be sure to replace YOUR_KEY_HERE with your generated Key)

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Food%20Sh&sensor=false&radius=500&location=0,0&key=YOUR_KEY_HERE

6. Enjoy

Now you can use that URL above in your Android/iOS device.

Shot answered 27/12, 2013 at 7:40 Comment(4)
The answer given by @Arc makes this answer sound like an "insecure quick fix" as opposed to the correct production technique. But I'm still not sure. A browser key used in a regular web browser is highly exposed to theft and reuse (it's easy to fake REFERRER header). A browser key used in an Andriod/iOS app is much harder to steal - comb through the app binary or MIM attack on SSL connection to google. It's weird that Google leaves this so unclear.Mantilla
Kinda strange, but it does work. I cannot find any explicit reference to this in their docs. Thank you.Lanthanum
Kya Baat Hai... But why IOS|Android key not working properly?Sioux
Thanks! This worked for me in 2015, but the user interface changed a little since this answer. I had to enable "Google Places API Web Service" under APIs for this to work.Hyams
M
28

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.

If you would like to request this support, please file a Places API - Feature Request.

Mileage answered 7/2, 2013 at 5:51 Comment(4)
Thanks again, that shed a lot of light on this issue Was it mentioned somewhere in the documentation? It says there in the Autocomplete tutorial, that the API key 'should' be stored on a proxy server, but that leaves many of us to think we can just use it directly from the app anyway.Malapropism
It isn't mentioned in the Places API documentation, however it is mentioned in the APIs console help: "Note that Android keys are only supported by some APIs".Mileage
and what if I want just test it from my webbrowser, there is no chance to work?Parchment
Hi,I have same the problem, In my app need to show search places in AutocompleteView but it give "request denied". please see my question " #20017594". how do you solved?. please help me.Garretson
A
5

https://developers.google.com/places/training/autocomplete-android

Storing your API key

Although the above code demonstrates how to communicate directly between an Android app and the Places Autocomplete service, you should not store your Places API key with your app.

You should therefore build a web application that stores your API key and proxies the Places API services. In order to secure communication between your Android app and the proxy web service, you should require user authentication to your proxy web service. Your Android app can securely store user credentials and pass them to your web service, or the user can log into your web app via an Android WebView.

For the latter approach, your web app should create and return a user authentication token to your Android app, and your Android app should subsequently pass this token to your proxy web service.

Abroad answered 2/8, 2013 at 1:42 Comment(3)
This is related to key security and not to solving the OP's questionQuinonoid
this does answer the question, a quick fix is t use a browser key and allow any referer but the method describes the documentation is the way to go.Etch
This answer really should be voted much higher. Although the top rated answer shows a workaround for using an API key directly on the device, Google's recommendation is to not store credentials directly on the device as they can be easily retrieved.Bortman
T
1

Go to google cloud platform console>Credentials click on edit by selected your YOUR_API_KEY>Application restrictions > select none option>save thats it.

If you select the android apps option from Application restrictions then google deny the place API with exception REQUEST_DENIED.

Teletype answered 10/5, 2020 at 9:52 Comment(1)
If you do this on a mobile application, your API key can be used by anyone. Simply unpack the app archive and extract the key from the source. Do not do this.Conveyor
I
0

In Google dev console, you should be able to find both "Places API" and "Places API for Android"

dev console search

Make sure to use "Places API for Android"

For some reason, "Places API for Android" is hidden in the API list, but can be accessed using search.

Intertidal answered 31/3, 2015 at 8:42 Comment(1)
Are you saying you've secured your Google Places API for Android key using SHA1 fingerprint + package name and are executing calls directly from your app to API and you're not getting Request_Denied? I've done this and still see Request_Denied.Ludie
A
0

I had the same issue , I fix it by leaving

Accept requests from these HTTP referrers (web sites) (Optional)

in browser key Empty

Antiquated answered 24/2, 2016 at 23:0 Comment(0)
H
0

I am still new, so I cannot comment, but to shed some light on Moe's answer, I resolved some similar Google Maps API issues regarding URL queries (for directions, using Volley) with the following steps:

  1. Get Android API Key (including Google Maps Directions API in my case).
  2. Get "Server" API Key (which seems to be created by using a key restriction of "HTTP referrers" these days - really, it's just used to issue URL queries through HTTP).
  3. Store the Android API key as a meta-data tag in the application tag in AndroidManifest.xml with android:name="com.google.android.maps.v2.API_KEY" and android:value as your key. This is used for direct interaction with the Maps API (minus URL queries).
  4. Use the server API key whenever issuing URL queries.

I am not sure if this also applies to URL queries for the Places API, if you only need the server API key, or if there is a better solution, but this worked for me.

I imagine that it works with just the first key - the one not restricted to Android.

Honewort answered 17/7, 2017 at 18:3 Comment(0)
P
0

Inside Google Cloud Console type Places and Activate it. Create an API Key and insert it onto your Android Studio App as you would do normally. That`s it.

Prevocalic answered 9/9, 2019 at 2:19 Comment(0)
C
0

I had the same problem. For me the key was to enable billing on project. I am still using "Applications for Android" restrictions. After setting up the payment method, Places Api started working.

Prior to using the Places SDK for Android, do the following:

  • Follow the Get an API Key guide to get, add, and restrict an API key.
  • Enable billing on each of your projects.
  • Enable the Places API for each of your projects.

See it there.

Be sure also to check out the billing plans for the Google Places API as it is not free!

Compaction answered 4/2, 2020 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.