Places API not accepting referer

一世执手 提交于 2019-12-24 06:59:11

问题


I've read almost all posts refering to this issue. Most of the answers were "Use Javascript API instead". I don't think that is a valid answer. I'm trying to set the referers on the Google's API Console so I can test both locally and from my dev server.

This is my API key from the Google's API console:

This is my request:

Request URL:https://maps.googleapis.com/maps/api/place/autocomplete/json?input=a&sensor=false&key=AIzaSyABBKjubUcAk69Kijktx-XXXXXXXXXX
Accept:*/*
Origin:http://localhost:5000
Referer:http://localhost:5000/users/profile/edit/location/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1

I'm getting the well-known error:

Origin http://localhost:5000 is not allowed by Access-Control-Allow-Origin.

I have also tried the "Any referer" API key with no success. Aren't this referers setted in order to allow this kind of AJAX calls? I'm running a Django app on a Gunicorn server, can it be something related to the '5000' port?


回答1:


Ok there is an other solution that should work:

Try using a ssh tunnel.

If you use localtunnel the setup is quite easy.

  • Step 1: Run sudo gem install localtunnel in your Terminal
  • Step 2: Run your local web server on any port! Let's say you're running Apache on port 8080.
  • Step 3: Now run localtunnel passing it the port to share. The first time you run localtunnel you have to point to a public SSH key. Check the README if you need help.

Here's an example: $ localtunnel -k ~/.ssh/id_rsa.pub 8080

You should see something like this: Port 8080 is now publicly accessible from http://8bv2.localtunnel.com ...

You can now put this URI into the Google Console.

But be aware that your localhost is publicly available when you use this solution.



来源:https://stackoverflow.com/questions/11967729/places-api-not-accepting-referer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!