Google Places REQUEST_DENIED from Server Request -

2019-07-21 14:23发布

After hours of searching and trying every possible solution found on the web, I cannot try anything else for my problem, so I really need help:

I want to implement a simple autocomplete text box with geocode results, so I call AJAX requests while the user types in the text box

  • I have enabled Google Maps and Google Places from the Google APIs Console
  • I have created a Key for server apps with my server's IP
  • I have a PHP file (called through AJAX) running on the server which sends the request to Google Places using file_get_contents() function (SSL is enabled) - also tried with cURL function
  • The request I'm asking for is

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=MY_SEARCH_STRING&language=us&types=geocode&sensor=false&key=MY_KEY

where MY_SEARCH_STRING is a simple string like "London" and MY_KEY the Key I have created

  • what I get as a response is

{ "predictions" : [], "status" : "REQUEST_DENIED" }

  • I have also tried this with a browser key. Also tried to create a new project, enable Services all over again, and create new Key. Switched services on/off & creating new key many times in any combination. Nothing worked.

  • The strange thing is that the same code was working the last months in a landing page I had created on the server, but had a long time to check it, so I do not know when it stopped working.

I appreciate a lot any help!! Thank you.

3条回答
倾城 Initia
2楼-- · 2019-07-21 15:05

I've had a similar issue, fixed it and discovered a few things that may be useful in troubleshooting this

  • using http instead of https will result in REQUEST_DENIED
  • omitting &userIp=x.x.x.x will result in REQUEST_DENIED
  • a server key needs to be generated and used in case the request is from a php script even if ONLY consumed via browser by users or it will result in REQUEST_DENIED
  • a few minutes are necessary before testing if the list of IPs allowed has been changed

Hope it helps some of you guys

查看更多
做个烂人
4楼-- · 2019-07-21 15:23

SOLVED. In Google API Console, I had declared allowed server IPs. I was assuming that if I declared an IP, I was just ensuring that requests would be allowed only from that IP. In order for this to work, you must also declare the allowed per-user limits for each IP, or else it just doesn't allow any requests. I removed all the allowed IPs, waited for 3-4 minutes, and the request was allowed.

查看更多
登录 后发表回答