0

I'm just develop Maps in my app's, and i'm curious why i just can used my API KEY only once or twice, and after that i need to open the console and simply save it to makes my API KEY works again,

My question is:

  1. this is the behavior of API KEY itself or there's something wrong about my setup?
  2. should i have two API KEY (one for IP Address and Android Apps for the 2nd)? even I'm accessing URL in my apps?

below is the success pic: Success and below is the failure with full message:

{
   "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address <myIp>, with empty referer",
   "routes" : [],
   "status" : "REQUEST_DENIED"
}

Failed

EDITED:

I have add my restriction key on google console like this: enter image description here

Milad Bahmanabadi
  • 946
  • 11
  • 27
flix
  • 1,688
  • 3
  • 34
  • 64
  • Off the top of my head, maybe you hit your daily usage quota. If not, then maybe you aren't using the key you think you are. Do you have a key `com.google.android.geo.API_KEY` defined in your AndroidManifest.xml file? – Tim Biegeleisen Dec 03 '18 at 06:33
  • @TimBiegeleisen sure, I've add `com.google.android.geo.API_KEY` and `MyApiKey` in `meta-data` tag – flix Dec 03 '18 at 06:38

1 Answers1

4

In cloud console you should set application restrictions for API key, you can choose one of this:

  • None
  • HTTP referrers (web sites)
  • IP addresses (web servers, cron jobs, etc.)
  • Android apps
  • iOS apps

Based on your error message i think you restricting based on IP address.

Alex
  • 9,102
  • 3
  • 31
  • 35
  • @TimBiegeleisen i think his IP changing every couple of days, and then he creating a new API key – Alex Dec 03 '18 at 06:39
  • Add that to your answer, then delete the comments :-) – Tim Biegeleisen Dec 03 '18 at 06:40
  • @Alex I have add my restriction key so i can use the key for development purpose, but the problem still appear like my 1st question – flix Dec 03 '18 at 06:40
  • @flix try to set the restriction to None, but better solution it is to use 'Android apps', this way you will restrict based on your package and SHA-1 – Alex Dec 03 '18 at 06:42
  • @Alex so the next question is how to call the URL from my apps and used my `android apps key`? for now i just used default URL like browser do in my apps `https://maps.googleapis.com/maps/api/directions/json?origin=LATLONG&destination=LATLONG&sensor=false&mode=driving&key=MyIpAddressKey` is there a better way? – flix Dec 03 '18 at 06:48
  • @flix directions api is a web service, you should restrict it with IP: https://stackoverflow.com/a/46185362/1268507 – Alex Dec 03 '18 at 06:59