javascript - Google Places API 返回错误:使用 Axios 时出现网络错误
问题描述
使用 python 请求并发送以下内容时
outs = requests.get("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.78257453407587,-117.11499507124117&radius=15000&keyword=Paddle+Board+Rentals&key=MY_KEY")
我得到一个状态 200 和结果。
当我使用 Axios 时
async getPlaces(point, radius, keywords, type=""){
const url = this.urlBuilder(point, radius, keywords, type);
const response = await axios.get(url)
.then(res => {return res})
.catch(err => {return err});
return response
}
和上面的python中的url完全相同,我得到了
Error: Network Error
python中是否有可能导致两个请求之间存在差异的默认标头?
编辑:使用 console.log 我能够得到这个错误
错误:禁止跨域 http://localhost
因此,使用 fetch 或 axios 运行 google places 请求存在问题,因为它们来自本地主机。
解决方案
问题是谷歌不允许用户使用 javascript 通过 https 进行这些网络调用。您必须使用 google places api。
推荐阅读
- java - 反序列化 GSON 中的字符串列表?
- installation - 如何以我已有的路径之间没有冲突的方式安装 Anaconda?
- c - 如何对指向有名字的地方的 void* 数组进行排序?
- zos - z/OS Unix 系统服务 BPXBATCH 以 CC=3840 结束
- rest - 休息 API 过滤器
- workflow - AEM 6.5 如何将系统用户添加到工作流管理员组
- r - 根据 r 中的预定义范围重新编码继续变量
- sql - 如何在 SQL 中向表中添加查询?
- asp.net-core - 在 .Net Core Web API 中跟踪数据库更改并使用 SignalR 向客户端发送相应推送通知的适当方法
- firebase - Firestore 数据库无法在线运行