-2

Please help me!

I am creating find near by places application in android, when i request for places using Unrestricted key. It will response me fully.

But after restricting Key with my project name, Released SHA1 and Debug SHA1 it will not responding and give me error. "This IP, site or mobile application is not authorized to use this API key. Ask Question".

  • I am requesting using HttpURLConnection,
  • My request code is

    StringBuilder googlePlaceUrl = new StringBuilder 
    ("https://maps.googleapis.com/maps/api/place/nearbysearch/json? 
      location=" + latitude + "," + longitude + "&rankby=distance&type="+ 
      nearbyPlace +"&key=xxxxxxxxxxx");
    

    In my manifest

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="xxxxxxxxx" />
    

I am not expecting this answer.

{ "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 103.24.99.82, with empty referer",
"routes" : [], "status" : "REQUEST_DENIED"
}
Android
  • 1,420
  • 4
  • 13
  • 23
  • So you are calling a Web API and configured your key to be Android only?. Shouldn't you be using the [Places SDK for Android](https://developers.google.com/places/android-sdk/signup)? – Morrison Chang Jan 02 '19 at 05:21
  • 4
    Have you Checked https://stackoverflow.com/questions/21933247/this-ip-site-or-mobile-application-is-not-authorized-to-use-this-api-key ? – ADM Jan 02 '19 at 05:22
  • Please review the types of API keys in [Using Google Maps API FAQ](https://developers.google.com/maps/faq#using-google-maps-apis) – Morrison Chang Jan 02 '19 at 16:22

1 Answers1

1

Go to Google API Console. Select your project and and click on the API Key you have created.

In that you will find Key Restriction. Please check restriction none. If you want to select Android then you need to add the package name of the Application and the SHA1 key. Make sure you entered the correct package name and SHA1 Key. If you have entered SHA1 key of your PC then it will not work in another pc if you are working in team. For that you need to add another SHA1 Key of that particular PC.

enter image description here

Chirag
  • 56,621
  • 29
  • 151
  • 198
  • But i have to restrict my key, coz i want to publish this. Without restriction it works fine. – Siddiq Athar Jan 02 '19 at 05:31
  • 1
    Then please check you have entered the correct SHA1 Key and package name. Please add SHA1 key of relese keystore and sign apk with that keystore – Chirag Jan 02 '19 at 05:33
  • After creating keystore successfully using keytool -list -v -keystore mystore.keystore "MYPATH/file.jks" I am still getting same error :( Should i use Unrestricted key and upload it? – Siddiq Athar Jan 02 '19 at 05:54
  • Google documentation is just saying to replaces the URL and key with your API KEY. I don't know what is difference between API key and Server Key. – Siddiq Athar Jan 03 '19 at 04:44