Kar*_*org 8 google-analytics google-api google-analytics-api
我们一直在使用Google Discovery API进行分析设置以发出请求:“ https://analytics.googleapis.com/ $ discovery / rest?version = v4”到目前为止,这种方法已经运行了两年多了,但是今天它开始回应:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://analytics.googleapis.com/$discovery/rest?version=v4 returned "The request is missing a valid API key.">
Run Code Online (Sandbox Code Playgroud)
我似乎无法在此api上找到任何状态,但感觉好像有些变化。
手动测试已经执行,我一直在重复该问题。
>>> credentials = oauth2client.client.GoogleCredentials("<redacted>", "<redacted>", "<redacted>", "<redacted>", None, "https://accounts.google.com/o/oauth2/token", "UserAgentHere")
>>> credentials
<oauth2client.client.GoogleCredentials object at 0x7f533eaf60b8>
>>> import httplib2
>>> http = credentials.authorize(http=httplib2.Http())
>>> http
<httplib2.Http object at 0x7f533eaf6390>
>>> from apiclient.discovery import build
>>> build("analytics", "v4", http=http, cache_discovery=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/googleapiclient/discovery.py", line 232, in build
raise e
File "/usr/lib/python3.6/site-packages/googleapiclient/discovery.py", line 224, in build
requested_url, discovery_http, cache_discovery, cache, developerKey)
File "/usr/lib/python3.6/site-packages/googleapiclient/discovery.py", line 277, in _retrieve_discovery_doc
raise HttpError(resp, content, uri=actual_url)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://analytics.googleapis.com/$discovery/rest?version=v4 returned "The request is missing a valid API key.">
>>>
Run Code Online (Sandbox Code Playgroud)
尝试将DiscoveryServiceUrl更改为
' https://analyticsreporting.googleapis.com/ $ discovery / rest?version = v4'
例:
build("analytics", "v4", http=http, cache_discovery=False,
discoveryServiceUrl='https://analyticsreporting.googleapis.com/$discovery/rest?version=v4'
)
Run Code Online (Sandbox Code Playgroud)
但它仅适用于报告,不适用于管理API
更新:
您还可以将服务名称从“ analytics”更改为“ analyticsreporting”。
build("analyticsreporting", "v4", http=http, cache_discovery=False,)
Run Code Online (Sandbox Code Playgroud)
“ analytics”服务名称用于“ api版本3”,并且在所有范围中都相同。如果您使用的是“报告核心API v4”,则应将名称更改为“ analyticsreporting”。
| 归档时间: |
|
| 查看次数: |
645 次 |
| 最近记录: |