本文整理汇总了Python中oauth2client.client.flow_from_clientsecrets方法的典型用法代码示例。如果您正苦于以下问题:Python client.flow_from_clientsecrets方法的具体用法?Python client.flow_from_clientsecrets怎么用?Python client.flow_from_clientsecrets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.client
的用法示例。
在下文中一共展示了client.flow_from_clientsecrets方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_credentials
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def get_credentials():
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
credential_path = settings.creds_path + ".youtube-upload-credentials.json"
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(settings.google_cred_upload, 'https://www.googleapis.com/auth/youtube.upload')
flow.user_agent = 'youtube-upload'
credentials = tools.run_flow(flow, store)
return credentials
开发者ID:HA6Bots,项目名称:Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader,代码行数:19,代码来源:videouploader.py
示例2: _get_credentials
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def _get_credentials(self):
"""Get OAuth credentials
:return: OAuth credentials
:rtype: :class:`oauth2client.client.Credentials`
"""
credential_dir = join(self.var_dir, 'cached_oauth_credentials')
if not exists(credential_dir):
makedirs(credential_dir)
credential_path = join(credential_dir, 'googleapis.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(self.config['creds'],
self.config['scope'])
flow.user_agent = 'Iris Gmail Integration'
credentials = tools.run_flow(
flow,
store,
tools.argparser.parse_args(args=['--noauth_local_webserver']))
logger.info('Storing credentials to %s', credential_path)
else:
credentials.refresh(self.http)
return credentials
示例3: get_oauth2_creds
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def get_oauth2_creds():
'''Generates user credentials.
Will prompt the user to authorize the client when run the first time.
Saves the credentials in ~/bigquery_credentials.dat.
'''
flow = flow_from_clientsecrets('edx2bigquery-client-key.json',
scope=BIGQUERY_SCOPE)
storage = Storage(os.path.expanduser('~/bigquery_credentials.dat'))
credentials = storage.get()
if credentials is None or credentials.invalid:
flags = tools.argparser.parse_args([])
credentials = tools.run_flow(flow, storage, flags)
else:
# Make sure we have an up-to-date copy of the creds.
credentials.refresh(httplib2.Http())
return credentials
示例4: build_service
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def build_service(secret, credentials):
"""
Build reference to a BigQuery service / API.
Parameters
----------
secret : string
Path to the secret files
credentials : string
Path to the credentials files
Returns
-------
out : object
The service reference
"""
flow = flow_from_clientsecrets(secret, scope="https://www.googleapis.com/auth/bigquery")
storage = Storage(credentials)
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run_flow(flow, storage, tools.argparser.parse_args([]))
http = credentials.authorize(httplib2.Http())
return build("bigquery", "v2", http=http)
示例5: get_credentials
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def get_credentials():
"""
credentialsファイルを生成する
"""
dirname = os.path.dirname(__file__)
credential_path = os.path.join(dirname, CREDENTIAL_FILE)
client_secret_file = os.path.join(dirname, CLIENT_SECRET_FILE)
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
credentials = tools.run_flow(flow, store)
print('credentialsを{}に保存しました'.format(credential_path))
return credentials
示例6: _get_credentials
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def _get_credentials(conf):
"""Gets valid user credentials from storage.
If nothing has been stored, or if the stored credentials are invalid,
the OAuth2 flow is completed to obtain the new credentials.
Returns:
Credentials, the obtained credential.
"""
store = Storage(conf.CREDENTIAL_FILE)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(conf.CLIENT_SECRET_FILE, conf.SCOPES)
flow.user_agent = conf.APPLICATION_NAME
# avoid mess with argparse
sys.argv = [sys.argv[0]]
credentials = tools.run_flow(flow, store)
print('Storing Google Calendar credentials to', conf.CREDENTIAL_FILE)
return credentials
示例7: get_flow
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def get_flow(secret, scope, redirect):
"""
Retrieve an authentication flow object based on the given
configuration in the secret file name, the authentication scope,
and a redirect URN
"""
key = (secret, scope, redirect)
flow = FLOWS.get(key, None)
if flow is None:
msg = MISSING_CLIENT_MSG % secret
if not os.path.exists(secret):
raise AuthenticationConfigError(msg)
flow = oauth.flow_from_clientsecrets(secret, scope,
redirect_uri=redirect,
message=msg)
FLOWS[key] = flow
return flow
示例8: main
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def main():
description = (
'Obtain a Google Spreadsheets authorization token using credentials.json.'
'To obtain the credentials.json file, follow instructions on this page:'
'https://developers.google.com/sheets/api/quickstart/python'
'Save credentials.json in the same directory with this script.'
)
parser = argparse.ArgumentParser(
description=description,
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[tools.argparser])
flags = parser.parse_args()
home = str(Path.home())
cachedir = os.path.join(home, '.cache', 'ingress-fieldmap')
Path(cachedir).mkdir(parents=True, exist_ok=True)
tokenfile = os.path.join(cachedir, 'token.json')
store = file.Storage(tokenfile)
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store, flags)
if creds:
print('Token saved in %s' % tokenfile)
示例9: reauth
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def reauth(self):
# Set up the Drive v3 API
SCOPES = ["https://www.googleapis.com/auth/drive"]
store = file.Storage('credentials.json')
credentials = store.get()
if not credentials or credentials.invalid:
try:
flow = client.flow_from_clientsecrets(GoogleAPI.CLIENT_SECRET, SCOPES)
credentials = tools.run_flow(flow, store)
except ConnectionRefusedError:
print("{!s} Make sure you've saved your OAuth credentials as {!s}".format(
GoogleAPI.ERROR_OUTPUT, GoogleAPI.CLIENT_SECRET))
sys.exit(
"If you've already done that, then run uds.py without any arguments first.")
self.service = build('drive', 'v3', http=credentials.authorize(Http()))
return self.service
示例10: main
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def main():
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('gmail', 'v1', http=creds.authorize(Http()))
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', [])
if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
示例11: _get_credentials
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def _get_credentials(self):
"""Get OAuth credentials
:return: OAuth credentials
:rtype: :class:`oauth2client.client.Credentials`
"""
credential_dir = join(self.config['creds_cache_dir'], 'cached_oauth_credentials')
if not exists(credential_dir):
makedirs(credential_dir)
credential_path = join(credential_dir, 'googleapis.json')
store = Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(self.config['creds'],
self.config['scope'])
flow.user_agent = 'Iris Gmail Integration'
credentials = tools.run_flow(
flow, store, tools.argparser.parse_args(args=['--noauth_local_webserver']))
logger.info('Storing credentials to %s' % credential_path)
else:
credentials.refresh(self.http)
return credentials
示例12: OAuth2Login
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def OAuth2Login(client_secrets, credential_store, email):
scope='https://picasaweb.google.com/data/'
user_agent='myapp'
storage = Storage(credential_store)
credentials = storage.get()
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets(client_secrets, scope=scope, redirect_uri='urn:ietf:wg:oauth:2.0:oob')
uri = flow.step1_get_authorize_url()
webbrowser.open(uri)
code = raw_input('Enter the authentication code: ').strip()
credentials = flow.step2_exchange(code)
storage.put(credentials)
if (credentials.token_expiry - datetime.utcnow()) < timedelta(minutes=5):
http = httplib2.Http()
http = credentials.authorize(http)
credentials.refresh(http)
gd_client = gdata.photos.service.PhotosService(source=user_agent,
email=email,
additional_headers={'Authorization' : 'Bearer %s' % credentials.access_token})
return gd_client
示例13: get_google_login_url
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def get_google_login_url(self, oauth_redirect_uri=None, redirect_to_after_oauth=None):
if not oauth_redirect_uri:
oauth_redirect_uri = '%s%s' % (
'http://localhost:9095' if self.request.host.startswith('localhost')
else authentication.get_host_for_request(self.request),
'/_/auth/oauth2_callback')
if not redirect_to_after_oauth:
redirect_to_after_oauth = 'http://localhost:5007' if self.request.host.startswith('localhost') else '/'
self.session['redirect_to_after_oauth'] = str(redirect_to_after_oauth)
# http://oauth2client.readthedocs.io/en/latest/source/oauth2client.client.html
flow = flow_from_clientsecrets(get_path_to_oauth_secrets(),
scope='https://www.googleapis.com/auth/userinfo.email',
redirect_uri=oauth_redirect_uri)
self.session['pickled_oauth_flow'] = pickle.dumps(flow)
self.session['oauth_state'] = utils.generate_secret(32)
try:
return str(flow.step1_get_authorize_url(state=self.session['oauth_state']))
except TypeError:
# TODO: Fix breakage only appearing in tests.
return str(flow.step1_get_authorize_url())
示例14: test_downloads
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def test_downloads(self):
"""Shows basic usage of the Drive v3 API.
Prints the names and ids of the first 10 files the user has access to.
"""
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('/tmp/token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('../Data/credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('drive', 'v3', http=creds.authorize(Http()))
file_id = '1H0PIXvJH4c40pk7ou6nAwoxuR4Qh_Sa2'
request = service.files().get_media(fileId=file_id)
request.execute()
示例15: _youtube_authentication
# 需要导入模块: from oauth2client import client [as 别名]
# 或者: from oauth2client.client import flow_from_clientsecrets [as 别名]
def _youtube_authentication(client_filepath, youtube_scope=_READ_ONLY):
missing_client_message = "You need to populate the client_secrets.json!"
flow = flow_from_clientsecrets(client_filepath,
scope=youtube_scope,
message=missing_client_message)
dir = os.path.abspath(__file__)
filepath = "{}-oauth2.json".format(dir)
# TODO: Determine if removing file is needed
# remove old oauth files to be safe
if os.path.isfile(filepath):
os.remove(filepath)
storage = Storage(filepath)
credentials = storage.get()
if credentials is None or credentials.invalid:
args = Namespace(auth_host_name='localhost',
auth_host_port=[8080, 8090],
noauth_local_webserver=False,
logging_level='ERROR')
credentials = run_flow(flow, storage, args)
return build(_YOUTUBE_API_SERVICE_NAME,
_YOUTUBE_API_VERSION,
http=credentials.authorize(httplib2.Http()))