-1

I created using googlemap api program.
I didn't restrict api in develop.

enter image description here

I deployed the program to server then I turned on api restrict.
the program looks like a little slow and sometimes miss response.

I need stop a second for the program?
Or is the setting bad?

google map api document

def nearbysearch(apikey, place, centerlatlng, types, radius):
    '''
    dependency
    ----------
    Places API

    parameters
    ----------
    place: tokyo

    return
    --------
    a place\n
    place_id, rating\n
    e.g. CmRaAAAARRAYThPn0sTB1aE-Afx0_..., 4
    '''
    url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?' \
        'location={}&radius={}&type={}&keyword={}&' \
        'key={}'
    url = url.format(centerlatlng, radius, types, urllib.parse.quote(place), apikey)
    # print("nearbysearch:", url)
    res = urllib.request.urlopen(url)

    ////////////// time.sleep(1) ////////////// <- need??

    retvalue = None
    if res.code == 200:
        res_json = json.loads(res.read())
        if res_json.get("results"):
            retvalue = res_json["results"]
    return retvalue

query: ramen as japanese langage at shibuya

https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=35.6557695,139.7017417&radius=1500&type=restaurant&keyword=%E3%83%A9%E3%83%BC%E3%83%A1%E3%83%B3&key=MY_API_KEY

miss responce:

{
   "error_message" : "API keys with referer restrictions cannot be used with this API.",
   "html_attributions" : [],
   "results" : [],
   "status" : "REQUEST_DENIED"
}

setting: localhost is not working at restrict

http://127.0.0.1:8000/*
http://www.henojiya.net/*

enter image description here website:

http://www.henojiya.net/gmarker/

Used about 200 times. enter image description here

evan
  • 5,443
  • 2
  • 11
  • 20
yoshitaka okada
  • 113
  • 1
  • 12
  • 1
    How do you query the nearby search? At what rate? What error(s) do you get when it *"miss response"*? Also did you check the [usage limits](https://developers.google.com/places/web-service/usage-and-billing#other-usage-limits) in place and did you make sure your usage complies? – MrUpsidown Apr 03 '20 at 13:09
  • thank you. I added erroro information at post bottom. – yoshitaka okada Apr 03 '20 at 14:38
  • Google the error! It takes much less time than to open a question here and wait for someone to point you at the help page. https://developers.google.com/maps/faq#browser-keys-blocked-error – MrUpsidown Apr 03 '20 at 16:06
  • thank you! I posted official question from google api console. I recieve response then will post to here. – yoshitaka okada Apr 04 '20 at 01:12
  • I've removed your API key from your answer. Please don't share private API keys on public sites, and make sure you restrict them as per https://developers.google.com/maps/api-key-best-practices#restrict_apikey – evan Apr 06 '20 at 06:52
  • thank you. I was careless. – yoshitaka okada Apr 06 '20 at 11:32

1 Answers1

1

You're using the Nearby Search API web service which cannot work with an API key that is HTTP referrer restricted. You need a second API key, restricted by IP address.

Also, please don't restrict your API key to localhost if it's used publicly in production as that means anyone could use it (and generate charges on your account) from their own localhost.

Please check out the related answers below for more details:
Google Maps API is never satisfied
Google Play Security alert about Google Cloud Platform (GCP) API keys

Hope this helps!

evan
  • 5,443
  • 2
  • 11
  • 20