我尝试使用Google思域API https://developers.google.com/civic-information/docs/v2/representatives/representativeInfoByAddress中的representativeInfoByAddres
来请求一些数据,但是当我尝试调用execute()
时收到错误。
from apiclient.discovery import build
add = "24783 Oakwood Circle Anaheim CA 92801"
service = build('civicinfo','v2', developerKey="key")
rep = service.representatives().representativeInfoByAddress(address = add)
response = rep.execute()
返回
---------------------------------------------------------------------------
HttpError Traceback (most recent call last)
<ipython-input-82-9fe54b12a47f> in <module>()
2 service = build('civicinfo','v2', developerKey="drog")
3 rep = service.representatives().representativeInfoByAddress(address = no)
----> 4 response = rep.execute()
/Users/dany_user/anaconda/lib/python2.7/site-packages/oauth2client/_helpers.pyc in positional_wrapper(*args, **kwargs)
131 elif positional_parameters_enforcement == POSITIONAL_WARNING:
132 logger.warning(message)
--> 133 return wrapped(*args, **kwargs)
134 return positional_wrapper
135
/Users/dany_user/anaconda/lib/python2.7/site-packages/googleapiclient/http.pyc in execute(self, http, num_retries)
838 callback(resp)
839 if resp.status >= 300:
--> 840 raise HttpError(resp, content, uri=self.uri)
841 return self.postproc(resp, content)
842
HttpError: <HttpError 403 when requesting https://www.googleapis.com/civicinfo/v2/representatives?alt=json&key=drog&address=24783+Oakwood+Circle+Anaheim+CA+92801 returned "Project 897797812785 is not found and cannot be used for API calls.">
我做错了什么?
答案 0 :(得分:1)
问题是需要启用API才能工作。
访问https://console.developers.google.com并确保&#34; API&#34;您已启用所需的API