-2

Env:

  1. project with reactjs
  2. using https://tomchentw.github.io/react-google-maps/ (Map with a SearchBox)

I have problem about restriction api key google, and the problem :

step to reproduce

  1. copy the project reactjs maps from https://stackblitz.com/edit/react-5bsr3p
  2. change with your key with key restriction -> application restriction -> ip address your ip address or get from link get ip on

Geocode.setApiKey('');

  1. run the project, go to tab network and I get error from

https://maps.google.com/maps/api/geocode/json?latlng=48.8583701,2.2922926&key=yourkey

like this

This IP, site or mobile application is not authorized to use this API key. Request received from IP address 114.124.192.77, with referer: http://localhost:3000/

Thanks for your help....

wuku
  • 135
  • 1
  • 9
  • 1
    It's not clear what API you are trying to use and to restrict. Is it the [Geocoding API](https://developers.google.com/maps/documentation/geocoding/overview) or the [Geocoding service](https://developers.google.com/maps/documentation/javascript/geocoding) of the Javascript API? If it's the Geocoding API (web service) then only IP address restrictions will work. You should refer to https://developers.google.com/maps/api-security-best-practices – MrUpsidown Jul 29 '21 at 09:31
  • @MrUpsidown it's use Geocoding API. My project hitting the url [link](https://maps.googleapis.com/maps/api/geocode/json?latlng=-6.312990199999999%2C106.9973014&key=the_key&language=en). So I think it's Geocoding API and the error like what i said before **"This IP, site or mobile application is ...."** – wuku Jul 29 '21 at 11:16
  • 1
    Please edit and clarify your question. We don't need that entire history of what you read, heard or saw here and there, etc. The link you provided in your comment works fine if I use one of my API keys. It is the Geocoding API (web service). So again, you **can't** use HTTP referrers with the web service. You need **IP based** restrictions. You haven't shared **how** you are sending the request and from where. Have you tried at all with an unrestricted key? Does it work? Have you tried generating a new key? etc. etc. etc. – MrUpsidown Jul 29 '21 at 12:27
  • From your description it sounds like you might be using the same key for both a request to the Geocoder web service and the Google Maps JavaScript API (hard to tell from the information in your question). You can't do that with a restricted key. – geocodezip Jul 29 '21 at 15:12
  • @MrUpsidown I have edit the post, actually added link stackblitz what I have done. – wuku Jul 29 '21 at 16:58
  • @geocodezip, yeah for now I using one key for Google Maps Javascript API and Geocoding API. So I have using different key ??? but take look this link https://stackblitz.com/edit/react-5bsr3p. It's just using Geocode API. And the console returning **"Error: This IP, site or mobile application is not authorized to use this API key. Request received from IP address 114.124.195.64, with referer: https://react-5bsr3p.stackblitz.io/. Server returned status code REQUEST_DENIED"** – wuku Jul 29 '21 at 17:01
  • @MrUpsidown You said it's work if you using your key. has that key restricted the IP addresses??? If I using key without restricted it's work perfectly too... – wuku Jul 29 '21 at 17:05
  • You can't use the same (restricted) key for the Google Maps Javascript API and the Geocoding API, you need a different (differently restricted) key for each. – geocodezip Jul 29 '21 at 17:48
  • @geocodezip example 1 key I set under **'Application restrictions'** -> ip address and **'API restrictions'** -> selected APIs (Geocoding API). The other key I set under **'Application restrictions'** -> ip address and **'API restrictions'** -> selected APIs (Maps Javascript API). Isn't that correct? If that's correct, I've done it and it's still the same. – wuku Jul 29 '21 at 22:31
  • No it's not. I pasted a link in my first comment which is the reference of what restrictions you should apply to what API. The JS API should be restricted with HTTP referrers. You haven't answered my question : have you tried generating a new key? How are you doing the request and from where? Are you sure you have set the right (public) IP as the restriction? You should edit your question and at least provide these details. If you don't want to or if you are sure the problem is not programming related (ie. defect key / account) then you should ask Google support, not Stack overflow. – MrUpsidown Jul 30 '21 at 07:16

1 Answers1

0

solving problem to access successfull with restriction ip address

wuku
  • 135
  • 1
  • 9