我正在使用 google admin api 并将示例代码放在一起并稍作修改。我在谷歌端正确设置了东西,但是当我运行脚本时它一直给我错误。下面是我在 python 中的代码:
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
SERVICE = build('admin', 'directory_v1', http=creds.authorize(Http()))
results = SERVICE.users().list(customer='my_customer', maxResults=10,
orderBy='email').execute()
users = results.get('users', [])
我得到的错误是这样的:
Traceback (most recent call last):
File "quickstart.py", line 11, in <module>
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
File "build/bdist.macosx-10.12-intel/egg/oauth2client/_helpers.py", line 133, in positional_wrapper
File "build/bdist.macosx-10.12-intel/egg/oauth2client/client.py", line 2125, in flow_from_clientsecrets
File "build/bdist.macosx-10.12-intel/egg/oauth2client/clientsecrets.py", line 165, in loadfile
File "build/bdist.macosx-10.12-intel/egg/oauth2client/clientsecrets.py", line 126, in _loadfile
File "build/bdist.macosx-10.12-intel/egg/oauth2client/clientsecrets.py", line 101, in _validate_clientsecrets
oauth2client.clientsecrets.InvalidClientSecretsError: Missing property "client_secret" in a client type of "installed".
我是 google api 的新手,非常感谢任何帮助。
谢谢
请您参考如下方法:
我发现的问题与 Google 的 OAuth 2.0 客户端 ID 的名称有关。对于您的客户端 ID,名称 必须完全 Google Sheets API Quickstart,否则 "client_secret" 将获胜当您从 Google 下载它时,它会填充到 client_secret.json 中。
或者,您可以在 installed JSON 对象下手动添加一个属性,例如 "client_secret":"mysupercoolsecret",使用为凭证生成的 secret ,当您制作凭证。
无论哪种方式,我都不知道为什么 Google 只会在凭证的name 不存在时填充 "client_secret" 字段匹配某个值。
希望这对您有所帮助。我在将 Google API 用于其他语言时也遇到过这个问题。
