首页 > 解决方案 > 如何修复“googlemaps.exceptions.ApiError:REQUEST_DENIED”

问题描述

这是我第一次使用谷歌地图 API 来获取数据。我已经需要一个来自谷歌云平台的 API 密钥。但是,它仍然会弹出这个错误“Googlemaps.exceptions.ApiError: REQUEST_DENIED (This API project is not authorized to use this API.)”。请帮忙!

# -*- coding: UTF-8 -*-
import io
import sys
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf8')
from googlemaps import Client
from pprint import pprint

API_KEY = 'MY_API_KEY'

gmaps = Client(key=API_KEY)
geocode_result = gmaps.geocode("臺北市")
pprint(geocode_result)
googlemaps.exceptions.ApiError: REQUEST_DENIED (This API project is not authorized to use this API.)

标签: pythongoogle-mapsgoogle-maps-api-3google-geocoding-api

解决方案


要使用 Geocoding API Web 服务,您需要首先在您的项目中启用它。按照Google 指南中的步骤操作。还要确保您的 API 密钥受到适当限制

希望这可以帮助。


推荐阅读