【发布时间】:2019-03-13 13:56:13
【问题描述】:
我正在学习使用 api,现在我尝试从控制台获取运行 python 脚本的设备列表。已安装 Python 客户端库。
sample.py
import pprint
import sys
from apiclient.discovery import build
import json
api_key = 'AIzaSyBNv8k-zm_TkytbBMJVkR7_wjc'
service = build('androidmanagement', 'v1', developerKey=api_key)
response = service.enterprises().devices().list(parent="enterprises/LC03w9087868").execute()
pprint.pprint(response)
我得到了错误
HttpError 401 when requesting https://androidmanagement.googleapis.com/v1/enterprises/LC03w9087868/devices?key=AIzaSyBNv8k-zm_TkytbBMJVkR7_wjc&alt=json returned "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.">
我需要在代码中添加什么来自动进行身份验证?
【问题讨论】:
-
API 密钥是有效的凭证吗?该错误表明它不是。
-
@tehhowch 我试过用新的钥匙,但结果是一样的。
-
您是否查看过任何官方文档,尤其是快速入门或示例页面?您是否查看了
developerKey参数对 Python 客户端库的含义? (提示:API 密钥不足以授权您) -
@tehhowch 我明白了,但你能给我更多信息或代码示例吗?
-
转到文档。查看快速入门和示例页面。他们有工作代码示例!
标签: android python google-api google-api-python-client android-management-api