ValueError: Client secrets must be for a web or installed app

7 浏览
0 Comments

ValueError: Client secrets must be for a web or installed app

我正在运行Python Quickstart下的quickstart.py示例代码,并且遇到以下错误:

ValueError: 客户端密钥必须用于网络或安装的应用程序。

我创建了一个具有项目所有者权限的credentials.json文件。

错误发生在以下代码段中:

if os.path.exists('token.pickle'):
    with open('token.pickle', 'rb') as token:
        creds = pickle.load(token)
# 如果没有有效的凭据可用,让用户登录。
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
        creds = flow.run_local_server()
    # 保存凭据以供下次运行使用
    with open('token.pickle', 'wb') as token:
        pickle.dump(creds, token)

我还注意到token.pickle文件没有被创建。这是错误输出:

File "updateSlidev01.py", line 51, in

main()

File "updateSlidev01.py", line 31, in main

flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)

File "/Library/Python/2.7/site-packages/google_auth_oauthlib/flow.py", line 174, in from_client_secrets_file

return cls.from_client_config(client_config, scopes=scopes, **kwargs)

File "/Library/Python/2.7/site-packages/google_auth_oauthlib/flow.py", line 147, in from_client_config

'Client secrets must be for a web or installed app.')

ValueError: 客户端密钥必须用于网络或安装的应用程序。

0