【发布时间】:2019-10-20 01:33:39
【问题描述】:
我在 Python Quickstart 下运行 quickstart.py 示例代码,我收到以下错误:
ValueError:客户端密码必须用于 Web 或已安装的应用程序。
我创建了一个具有项目所有者权限的 credentials.json 文件。
错误发生在以下一段代码中:
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
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()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
我还注意到 token.pickle 文件没有被创建。这是错误输出:
File "updateSlidev01.py", line 51, in <module>
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: Client secrets must be for a web or installed app.
【问题讨论】:
-
您是如何创建该 credentials.json 文件的?
-
嗨!这正是问题所在。我回答了下面的问题。非常感谢!
标签: python google-api google-api-python-client