Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 370
Stefan Malacu Avatar asked Feb 01 '13 20:02

Stefan Malacu


People also ask

Why Google Places API is not working?

It looks like you try to use Web Service, not Places API for Android. In this case you cannot apply an API key with Android app restriction. Web Service requires a different API key. You can generate the new one, the only restriction that you can use with web services is by IP.

Where do I get Google Places API key Android?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.

How Use Google Places Autocomplete Android?

The autocomplete widget is a search dialog with built-in autocomplete functionality. As a user enters search terms, the widget presents a list of predicted places to choose from. When the user makes a selection, a Place instance is returned, which your app can then use to get details about the selected place.

Why can't I get an API key for Google Places?

The TL;DR version of that link is that Google Places API doesn't support the Android/iOS key option, only the server option. Second, and this goes without saying, make sure you're passing the key to the GooglePlaces instance. Lastly, if you're restricting use of the API key by IP make sure your request is coming from an allowed address.

Is there an API for place autocomplete?

If you're building a client-side application, take a look at the Places SDK for Android, the Places SDK for iOS, and the Places Library, Maps JavaScript API . The Place Autocomplete service is a web service that returns place predictions in response to an HTTP request. The request specifies a textual search string and optional geographic bounds.

What is the places SDK for Android autocomplete service?

The autocomplete service in the Places SDK for Android returns place predictions in response to user search queries. As the user types, the autocomplete service returns suggestions for places such as businesses, addresses, plus codes, and points of interest.

How do I know if a Google API request was successful?

Ensure that the logo and copyright notice are visible, and display the "powered by Google" logo if you're using data without a map. Status codes returned by service. OK indicating the API request was successful. ZERO_RESULTS indicating that the search was successful but returned no results.


1 Answers

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.

like image 191
Moe Avatar answered Oct 05 '22 01:10

Moe