我想測試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密鑰讓我們通常集中更多的分析或代碼。 –