我想测试Google Genomics。我有一个项目,我可以从getting started with the api运行main.py。但这个文件皮张oauth2client的引擎盖下的凭证是如何产生的:如何在不使用argparser的情况下添加client_secret?
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)
有人能解释我这是什么码?我怎么能把它转换成没有争论的东西?
我试着用google-api文档的其他解决方案,但主要是我不明白正在做什么,所以我不明白我该怎么做。 (我也不完全了解OAuth2client) This answer建议argparse是强制性的。但this其他方式使用google-api-python-client不要使用它...
感谢保罗,我结束了与'服务=构建('基因组','v1beta2',developerKey = api_key)' – Llopis
API密钥伟大 - 你不会后悔:)是的使用API密钥让我们通常集中更多的分析或代码。 –