Place API for Android - android

I'm trying to use the Google Places API in my application. For that I need to generate Server Key.
I used my device IP address to generate a Server Key. My app works only in my device. If I use some other device I get an error:
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key.",
"predictions" : [],
"status" : "REQUEST_DENIED"
}
Could you please help me in this regards. How to generate Server key which works for all devices.

Try to create a new Places API key. When creating the key choose the server but leave the IP field blank (so as to allow any IP address).
Notify and vote up if it works.

Related

Google map API key not working properly in android app but IP address works properly

Downloaded URL: { "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 000.00.000.00, with empty referer", "routes" : [], "status" : "REQUEST_DENIED"}
i got this Error when i put SHA-1 and Package name to generate key , key generated but when i use it and run application some times it works limited (PlaceAutoComplete work) but on selection No Response and some times PlaceAutoComplete Also not works (when i write a single character PlaceAutoSearch option went closed),
if i give IP address of my device it works properly with tha same nothing to b change , just need to change google map API key settings from Android to IP address
Why it asked for IP authorization? why it not works on SHA-1 and Package name in Android
Help me Please

Api key request denied

I am trying do that drawing path between two location,when I try do this I got a error this.
I shared below my url and error.I created Android api key,wht I got request denied error from google api
url: https://maps.googleapis.com/maps/api/directions/json?origin=41.050399,28.940599&destination=41.1119857,29.0186137&sensor=false&mode=driving&alternatives=true&key=AIzaSyB9LW3JNai1tGYtSVZrRGMGeJ71q7Y3DbA
json:{
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 78.186.62.169, with empty referer",
"routes" : [],
"status" : "REQUEST_DENIED"
}
I dont think that is the correct way of using it, try something like this
https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY>&callback=initMap
and if it is in a variable then u will need " " like
src="https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY>&callback=initMap"
Directions API web service requires a Server API key, not Android API key.
Please look at the documentation:
https://developers.google.com/maps/documentation/directions/get-api-key#get-an-api-key

Getting : ipRefererBlocked on android app

I'm trying to use the "Google Identity Toolkit" with the "tutorial" android demo app, but now I get this error:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed."
}
}
Any Idea? In the Google console I need allow some thing? Where?
OAuth 2.0 client IDs:
Android,
Web application
And on Identity Toolkit API console, it allow I select "Web application" client ID in Google provider.
And I have set up this in my "tutorial" app
This error is usually caused when you are trying to run the code on a URL you didn't add to the referrer URLs in the console.
To fix this go to the Google Developer Console, then under API Manager click credentials and find your browser key. On this page you can add any URLs that will be using that key.
Remember it treats www. differently, so to cover all possible pages you could do this:
.domain.com/
domain.com/*
I figured out today that there is a bug when you create a new Android API key. You will have probably noticed that there was also a Browser API key that was generated when you created the Android API key. My Browser API key had no name, and was therefore not configurable. However, I performed a bit of URL manipulation magic to be able to access and edit my Browser API key. Here's what I did:
1) Click on the name of the Android API key
2) Edit the URL right before the ? such that the number before the ? matches the (0-based) index of the position of your Browser API key. That is, if your browser api key appears second in your list of two API keys, then your Android API key would have been first, at position 0. Therefore the URL would read something like this:
.../key/0?...
So now you want to change it to look like this:
.../key/1?...
3) From here you should be able to change your allowed referrers to
http://yourdomain.com/*
Then, so long as you have your keys set up properly everything should work as expected! Also, note that after you do this once you will then have a name for your browser key, and it will be easily editable in the future!
Best of luck!
You will need to...
Create an Android API Key
Set the package name and SHA-1 of your signing key file(see gitkit guide on how to do that)
Use that API Key for the identitytoolkit.api_key value

unable to get the routes from the google api

I got the api key by following the usual steps.
Then I was able to get map and use some inbuilt things on it like search etc
Then later I tried routing, I was unable to get the routes. When I pasted the request:
https://maps.googleapis.com/maps/api/directions/json?origin=28.6100,2077.2300&destination=18.9750,72.8258&key=mykey
on the browser I got the following and realized that I don't have the permission. I searched for this problem but couldn't find the solution, please help.
Response on browser:
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address xxxxxxxx, with empty referer",
"routes" : [],
"status" : "REQUEST_DENIED"
}
Make sure you are using server API key, not an Android key (mobile development). See this post:
Google Places API request denied for Android autocomplete, even with the right api key .
Also make sure you are sending the key to GooglePlaces instance.
If you are restricting use of API key by IP make sure your request is coming from an allowed address.

Why is my api key not accepted by the Google Directions (Android) request?

Whenever I include my Google Play Services API key along with my request for Google Directions like in the code below:
private String makeDirectionsURL(double originLat, double originLong, double destLat, double destLong)
{
StringBuilder url = new StringBuilder();
//first part of url//
url.append("https://maps.googleapis.com/maps/api/directions/json?");
//start adding parameters//
//origin coordinates
url.append("origin="+originLat+","+originLong);
//destiniation coordinates
url.append("&destination=");
url.append(destLat+","+destLong);
//api key
url.append("&key=");
url.append(getResources().getString(R.string.google_api_key));
//NOTE: for some reason, the request suceeds when leaving out the api key
return url.toString();
}
When I include the api key as a parameter in the request, the json response shows that my request has been denied. The response reads:
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key.",
"routes" : [],
"status" : "REQUEST_DENIED"
}
Yet the same api key works for my google map view - and my api console registers the accesses for the map view quota limit. Even odder yet, when I leave out the key parameter in the Directions request I get a valid JSON response.
I have a feeling that I have to generate another different api key for just the Google Directions service - but I'm not sure how to. The documentation here:
https://developers.google.com/maps/documentation/directions/#api_key
Says to visit the console and activate the Directions API service - I did.
Then it says my api key "will be available from the API Access page, in the Simple API Access section. Directions API applications use the Key for server apps." Now is where I'm confused - how can I use the key for server apps if I am accessing from a mobile device - I'm assuming this is for any webpages that wish to use the service - but what do I do for an android app. As I said, I already tried using my Simple API Access key for Android apps, which I know works, yet when I pass the same key to Google Directions - it mysteriously doesn't work...
Any help, vague guidance, or links to read up on would be really appreciated.
PS: If I can't figure this out - am I allowed to keep sending requests w/o a api key?
I think the issue is because you are trying to pass a server key which is directly tied to your server's IP address, when you should be passing an android app key.
In your Google APIs console, navigate to API's and Auth. From here you can create a new public API key.
When prompted, select Android Application
You will need to enter your device's SHA1 Certificate Fingerprint
This comes from the keystore used to sign the apk. When running an app in debug, you will most likely be using your IDE's debugging keystore. Google has a nice write up on how to get this information.
When releasing the app, you will need to sign it with your own key. You will either need to edit your API key to the new keystore SHA1 fingerprint or create a new API key.
Additionally, according to Google, you should be using a key.
All Directions API applications should use an API key. Including a key
in your request:
Allows you to monitor your application's API usage in the APIs
Console. Enables per-key instead of per-IP-address quota limits.
Ensures that Google can contact you about your application if necessary.
While I can't comment on how strictly they enforce this, I strongly encourage you to do so to avoid any issues down the road.

Categories

Resources