0

I am running a copy of the website that I am working on, using a server that runs on localhost:8759. The website uses Google's address autocomplete capability. I have a script element at the bottom of the page with a URL of https://maps.googleapis.com/maps/api/js?key=XXXXXX&libraries=places, with an actual API key in place of the XXXXXX. The API key is restricted so it can only be used from our production and testing servers.

I would like it to work on localhost instead. Initially, I tried running the website on localhost, and the autocomplete didn't work. I saw an error on my console saying Google Maps API error: RefererNotAllowedMapError.

I went to Google's Developer Console, added localhost:8759/* to the list of referrers, and waited over 5 minutes as recommended by Google. The autocomplete still didn't work. I saw an error saying This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console.

I tried adding a key with no restrictions and using it. The autocomplete still didn't work. I got an error like the one mentioned in the previous paragraph.

The autocomplete works fine when it is on a page coming from our testing server (which has an IP address in the list of referrers) or production (which has a domain in the list of referrers), but I can't make it work on localhost.

How can I make it work?

miguev
  • 4,481
  • 21
  • 41
Elias Zamaria
  • 96,623
  • 33
  • 114
  • 148
  • I figured out a way to run my personal development server using a real IP address. This problem is no longer important to me. I may continue to peek in here, try what people suggest, and post about what happens, in case I may be of use to anyone else. – Elias Zamaria Jun 29 '17 at 05:21

1 Answers1

0

In my experience omitting slashes and protocol but including port seems to work: Eg: localhost:5000 or localhost:8759 in your case

chaduhduh
  • 80
  • 4
  • I am kind of confused about why omitting the slashes and protocol from the domain in the restrictions would make it work, when it doesn't work with a key with no restrictions at all. But I tried what you suggested and still got the error saying `This API project is not authorized to use this API`. – Elias Zamaria Jun 28 '17 at 23:44
  • 1
    It sounds like then you haven't enabled the API for the project which has an activated key. Likely not an issue with the key restrictions. Make sure you click "Enable API" and select the API you want to use for the project. Have you done that step? [link](https://www.screencast.com/t/yo81WN8SYT) – chaduhduh Jun 29 '17 at 02:06