我正在玩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的新手,非常感谢任何帮助。
由于
答案 0 :(得分:0)
我发现的问题是Google的 OAuth 2.0客户端ID 的名称。对于您的客户ID,名称必须完全为Google Sheets API Quickstart
,否则"client_secret"
将不会填充client_secret.json
当你从谷歌下载它。
或者,您可以使用在创建凭据时为凭据生成的秘密在installed
JSON对象(例如"client_secret":"mysupercoolsecret"
)下手动添加属性。
无论哪种方式,我都不知道为什么Google只会在凭据的 名称 与特定值不匹配时填充"client_secret"
字段。
希望这会有所帮助。我也将此问题与其他语言的Google API一起使用。
答案 1 :(得分:-1)
再次下载client_secret.json
。该文件存在问题。
您可以使用this link获取小型教程来获取client_secret
。