如何在Google Calendar API中使用run_flow()?
作者:互联网
我正在尝试使用the sample described in the docs对Google Calendar API进行身份验证:
from oauth2client import file
from oauth2client import client
from oauth2client import tools
CLIENT_SECRETS = 'client_secrets.json'
FLOW = client.flow_from_clientsecrets(CLIENT_SECRETS,
scope=[
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.readonly',
],
message=tools.message_if_missing(CLIENT_SECRETS))
storage = file.Storage('sample.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run_flow(FLOW, storage, auth_host_name='localhost', auth_host_port=[8080, 8090],
logging_level='ERROR', noauth_local_webserver=False)
此代码失败
Traceback (most recent call last):
File "C:/infoscreen/testgoogle.py", line 18, in <module>
logging_level='ERROR', noauth_local_webserver=False)
File "C:\infoscreen\oauth2client\util.py", line 132, in positional_wrapper
return wrapped(*args, **kwargs)
TypeError: run_flow() got an unexpected keyword argument 'auth_host_name'
It presumes it is run from a command-line application and supports the
following flags:–auth_host_name: Host name to use when running a local web server
to handle redirects during OAuth authorization.
(default: ‘localhost’)
我的代码出了什么问题?
解决方法:
我迟到了一个月,但我会试一试.
我查看了文档,并在标志部分下找到了它:
The tools module defines an ArgumentParser the already contains the flag
definitions that run() requires. You can pass that ArgumentParser to your
ArgumentParser constructor:
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[tools.run_parser])
flags = parser.parse_args(argv)
因此,似乎您不应该将标志添加为参数,而是从命令行添加它们,然后使用Google的ArgumentParser返回“flags”对象,然后将其添加为第三个位置参数.
标签:python,api,google-api,google-calendar-api 来源: https://codeday.me/bug/20190831/1774487.html