我想测试谷歌基因组学。我有一个项目,我可以从api 开始运行main.py。但是这个文件隐藏在 oauth2client 的底层是如何生成凭据的:
import argparse
import httplib2
from apiclient.discovery import build
from collections import Counter
from oauth2client import tools
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run_flow
# For these examples, the client id and client secret are command-line arguments
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[tools.argparser])
parser.add_argument('--client_secrets_filename',
default='client_secrets.json',
help='The filename of a client_secrets.json file from a '
'Google "Client ID for native application" that '
'has the Genomics API enabled.')
flags = parser.parse_args()
# Authorization
storage = Storage('credentials.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets(
flags.client_secrets_filename,
scope='https://www.googleapis.com/auth/genomics',
message='You need to copy a client_secrets.json file into this directory, '
'or pass in the --client_secrets_filename option to specify where '
'one exists. See the README for more help.')
credentials = run_flow(flow, storage, flags)
# Create a genomics API service
http = httplib2.Http()
http = credentials.authorize(http)
有人可以解释一下代码是什么吗?我怎么能把它转换成没有 argparse 的东西?
我尝试了 google-api 文档的其他解决方案,但重点是我不明白正在做什么,所以我不明白我应该做什么。(我也不完全了解 OAuth2client) 这个答案表明 argparse 是强制性的。但是这种使用 google-api-python-client 的其他方式不要使用它......