Places Api stopped working in android - android

I integrated Places API in my android project and it was working fine from past few months but suddenly it is giving me the following exception :-
This IP, site or mobile application is not authorized to use this API key. Request received from IP address 175.176.186.118, with empty referer
Please help me know what is the issue and how can i solve it.
I am using my Api key for getting the places response. It was working with my API key. I read on stack overflow that you need server key for this but i am unable to find any option for creating a server key.
Any help will be apreciated, Thank you.

Check your API Restrictions for your specific project in the Google API console. You can find it by navigating to your project on the console. Select credentials in the left tab and then select the "API restrictions" tab next to "Application restrictions" near the bottom of the page. From their, click the "Select API" drop down box and select Places SDK for Android. Or you can delete all the api restrictions to have no restrictions. Also check your application restrictions to restrict it to android apps if you're not using servers to make the request. Here is a question I answered a few weeks ago on how to set that up.

Include a referrer in your network request.
Example: HTTP header "Referer:anmol.com"

Related

Getting Google Places API key for Android

Over the Past week i have been trying to Implement Google Places API for android , Google's developer page says that i need a api key and after researching many forums I got confused as to what key should I be using I tried using the Browser key, the Server Key and also the android Key, nothing seems to be working for me, I have already been able to use The Google Maps API v2 using the android key, but i am really confused, can someone help me out? The Webpages that i have been referring to are :
First [Link][1]
and Second Link
Please help me out ,also I am trying to develop the android app using Eclipse and ADT so some of the latest forums become obsolete for me, and since Google keeps changing the layout of their developer console its hard to keep a track of the older Guides Provided here
Thank You
This is what I have Done
As you can see I have enabled Places API
[enter image description here][4]
How about u directly read developer Guide for the keys u r so confused. I'm sure its gonna help just go through it once.
Below are the step to create places api key for Android.
Go to Google API console.
Click on the dropdown and select 'create a project'.
Enter Project Name.
now click on Navigation drawer and select API Manager.
Enable google places api.
Create Credentials Android Key.
Enter Key Name and then hit create.
Now u can use the Android key for google places api.
Now u can request for nearby places checkout this url.
It takes SERVER_Key
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=yourlatitude,yourlongitude&radius=5000&sensor=true&key=SERVERKEY
Click on New Credentials.
Select Server_key.
Enter IP if u want it for testing purpose otherwise leave it blank.
finally click on create.
now thats ur server_key. It takes sm time for google to activate the service so u may get an error "The provided API key is expired" while requesting places. Check it out after sm time and u shd be getting places response.
https://developers.google.com/android/ see what you cant to create .

Can I use Google Places API without a personal Website?

Ok, so, maybe I just do not understand the Google Places API, or maybe I have been failing miserably with following tutorials, but either way, I could definitely use some help.
I am making an android application where a screen zooms into where they are located and uses google places to search for a hard-coded String place.
(IE, you live in Los Angeles, California; the closest McDonald's to you is located here *). And then it would display the spot on the map.
When I follow every single tutorial I have found to get an API key for Google places, (IE: https://www.youtube.com/watch?v=8PVK1Ue5rvk) it says I need to enter a web address to obtain one (See pictures below)
-----(Gap inbetween photos)-------------------------------------------------
--
But I do not have a website or URL to put here as I am just writing this for my android device.
Do I need to get a website host URL in order to use this?
Is there a generalized URL we are supposed to use that I have not heard of?
Am I doing this entirely the wrong way?
I also copied and pasted code from here: http://www.androidhive.info/2012/08/android-working-with-google-places-and-maps-tutorial/
And I am able to run it, but the error I am receiving in the logcat is Places Status : REQUEST_DENIED
Which makes me think I need to change part of the code with a key of my own.
I do indeed already have a Google Maps API key which I am using here in the application.
Thanks in advance for your time and help all!
-Sil
EDIT: See additional picture:
See the [Android key] button next to the [Browser key] button you highlighted.
Click on that [Android key] button.
;)
Well, it turns out that my phrasing was just poorly worded :(
I rephrased what I was looking for here: How do I get a Google Places API key for my Android App
And the answer I received was:
Please Follow below steps
Visit the Google APIs Console at https://code.google.com/apis/console and log in with your Google account.
A default project called API Project is created for you when you first log in to the APIs Console. You can use the project, or create a new one by clicking the API Project button at the top of the window and selecting Create. Maps API for Business customers must use the API project created for them as part of their Places for Business purchase.
Click the Services link in the left-hand navigation panel.
Click the status switch (the on/off button) next to the Places API entry. The switch slides to ON.
Click API Access in the left-hand navigation panel.
Click Create new Server key. Enter one or more server IP addresses if you wish to restrict the servers that can send API requests.
Click Create. Your API key appears under the heading Key for server apps (with IP locking).
This solved the issue I was having entirely.
Thank you for taking the time to help Stephan, I appreciate it as you got me going in the right direction

This IP, site or mobile application is not authorized to use this API key - Android

I have a problem with connection with Google maps API V2 and Android. I' ve enabled services:
Google Maps Android API v2
Places API
Also I've added sha1 fingerprint.
But I still get this message: This IP, site or mobile application is not authorized to use this API key
I'm calling service from Android. Do you know where might be the problem, cause I don't know where to search.
You must be creating a browser key instead of an android key. I faced similar problem when I accidentely created an android key for Google Cloud Messaging instead of a server key. Please check which key is required for your purpose. For google maps v2 you need android key and for google places api you need a server key(searched google but not so sure on this one never used it). So basically you need two keys.
Update:
You need server key for places api.
Refer this tutorial.
http://www.androidhive.info/2012/08/android-working-with-google-places-and-maps-tutorial/
Step 1- Go to code.google.com/apis/console/?noredirect
Step 2- Create a new project
Step 3- Go to services and choose Places API, turn it on. This will ask your organization name and url.Fill them and click Ok.
Step 4- Now go to API Access and there will be your API Key. You don't have to click on Create new key. This will be your browser apps key which you can use in your Android Apps.
This solution worked for me perfectly.
If generating an Android App, the "Server" IP address could be any IP of any phone on any network. What do I write in the "Accept requests from these server IP addresses" box in order to have any IP address accepted?
Edit - Apologies. Apparently just leave it blank...
I just had this issue the other day, it is not actually an issue with this library.
First, make sure you're using a server API key, not an Android/iOS key (if you're doing mobile development). See this stackoverflow post: Google Places API request denied for Android autocomplete, even with the right api key . 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.
You don't need to create a key for using Google place API, instead just use "Key for browser apps (with referers)". But if you want to use Google Map API, you need to generate a Android Key, and you could find instruction here :https://developers.google.com/maps/documentation/android/start.
Good luck.
I got this problem too. but I SOLVED this issue only using something tricky. Go to your google console and create new key which is browser key, then let the column empty and save. you can use the key that has been created in you mobile apps now.
GOOD LUCK! *Unfortunately I can't post an image to this answer
Change your API key, you may use Android key in the URL. For to specify Key in the URL you need to get WEBSERVICE key.

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

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!
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.
2. Go into Credentials
Click CREATE NEW KEY under Public API Access
3. Select BROWSER KEY
4. Click Create, Nothing Else
Leave the HTTP Refer box empty.
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.
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.
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.
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.
In Google dev console, you should be able to find both "Places API" and "Places API for Android"
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.
I had the same issue , I fix it by leaving
Accept requests from these HTTP referrers (web sites) (Optional)
in browser key Empty
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:
Get Android API Key (including Google Maps Directions API in my case).
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).
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).
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.
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.
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!

Request denied while querying the google places api from my android application

I am building an android application that gets the users location and returns places that are nearby using the google places api.
I have an api key and I am using this url:
https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false?key=mykey
and I keep getting REQUEST_DENIED in my android application. The link works well on the browser and it returns a json.
It appears you have a question mark after sensor=false instead of an ampersand. Try this instead:
https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=mykey
I was having the same issue connecting to the Places API from my android app and receiving the request denied error. The following post resolved my problem. It explains that the Places API does not currently support Android or iOS keys generated from the API console at this time. I will be using the browser key for my app.
stackoverflow Places API Question
Hope this helps!
I was facing the same problem use Browser Key as your key on android.This worked for me. You don't need to fill any thing while creating browser key.

Categories

Resources