我有一个Google电子表格,我可以与我的用户一起访问,我希望通过Python 3.6作为Windows中的任务来阅读它。
我在这类事情上找到了一些很好的教程,因此我构建了以下内容:
def get_credentials():
# "Gets valid user credentials from storage."
credential_dir = os.getcwd();
credential_path = os.path.join(credential_dir, 'client_secret.json');
print(credential_path);
store = Storage(credential_path);
credentials = store.get();
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
credentials = get_credentials();
我在工作目录中创建了一个client_secret.json文件,这里是伪内容(结构未更改,但键已更改):
{"installed":{"client_id":"1002948203906-cpsdfyhbghjhtreetryy543f3q8m25kv.apps.googleusercontent.com","project_id":"MySolutionTst","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"ao2sDWEDTGVHWdddfuieXJqr","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
我认为一切都应该有效,但它会因为这些错误而失败:
C:\Users\MyUser\Documents\Visual Studio 2017\Projects\MySolution\MySolution\client_secret.json
Traceback (most recent call last):
File "C:\Users\MyUser\Documents\Visual Studio 2017\Projects\MySolution\MySolution\MySolution.py", line 135, in <module>
credentials = get_credentials();
File "C:\Users\MyUser\Documents\Visual Studio 2017\Projects\MySolution\MySolution\MySolution.py", line 67, in get_credentials
credentials = store.get();
File "C:\Program Files\Python36\lib\site-packages\oauth2client\client.py", line 407, in get
return self.locked_get()
File "C:\Program Files\Python36\lib\site-packages\oauth2client\file.py", line54, in locked_get
credentials = client.Credentials.new_from_json(content)
File "C:\Program Files\Python36\lib\site-packages\oauth2client\client.py", line 302, in new_from_json
module_name = data['_module']
KeyError: '_module'
Press any key to continue . . .
我仍然是Python的新手,绝对是Google Docs的新手,我看不出它出了什么问题。我可以想象的是client_secret.json的结构不正确,但我从Google API管理器下载了客户端密钥json文件,并从那里直接保存(并且没有做任何更改)。
除此之外,出了什么问题?
最诚挚的问候,