本文整理汇总了Python中google_auth_oauthlib.flow.InstalledAppFlow.from_client_config方法的典型用法代码示例。如果您正苦于以下问题:Python InstalledAppFlow.from_client_config方法的具体用法?Python InstalledAppFlow.from_client_config怎么用?Python InstalledAppFlow.from_client_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google_auth_oauthlib.flow.InstalledAppFlow
的用法示例。
在下文中一共展示了InstalledAppFlow.from_client_config方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CredentialsFlowWrapper
# 需要导入模块: from google_auth_oauthlib.flow import InstalledAppFlow [as 别名]
# 或者: from google_auth_oauthlib.flow.InstalledAppFlow import from_client_config [as 别名]
def CredentialsFlowWrapper(client, credentials_only=False, **kwargs):
# relax scope comparison, order and default scopes are not critical
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
# parse credentials from file or json
if RE_CREDENTIALS_JSON.match(client):
client_json = json.loads(client)
else:
with open(client, 'r') as json_file:
client_json = json.load(json_file)
if credentials_only:
return client_json
else:
if 'installed' in client_json:
flow = InstalledAppFlow.from_client_config(client_json, APPLICATION_SCOPES, **kwargs)
else:
flow = Flow.from_client_config(client_json, APPLICATION_SCOPES, **kwargs)
flow.user_agent = APPLICATION_NAME
return flow
示例2: main
# 需要导入模块: from google_auth_oauthlib.flow import InstalledAppFlow [as 别名]
# 或者: from google_auth_oauthlib.flow.InstalledAppFlow import from_client_config [as 别名]
def main(args=None):
if args is None:
args = sys.argv[1:]
options = parse_args(args)
setup_logging(options)
# We need full control in order to be able to update metadata
# cf. https://stackoverflow.com/questions/24718787
flow = InstalledAppFlow.from_client_config(
client_config={
"installed": {
"client_id": OAUTH_CLIENT_ID,
"client_secret": OAUTH_CLIENT_SECRET,
"redirect_uris": ["http://localhost", "urn:ietf:wg:oauth:2.0:oob"],
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token"
}
},
scopes=['https://www.googleapis.com/auth/devstorage.full_control'])
credentials = flow.run_local_server(open_browser=True)
print('Success. Your refresh token is:\n', credentials.refresh_token)
示例3: login
# 需要导入模块: from google_auth_oauthlib.flow import InstalledAppFlow [as 别名]
# 或者: from google_auth_oauthlib.flow.InstalledAppFlow import from_client_config [as 别名]
def login():
client_id = "769904540573-knscs3mhvd56odnf7i8h3al13kiqulft.apps.googleusercontent.com"
client_secret = "D2F1D--b_yKNLrJSPmrn2jik"
environ["OAUTHLIB_RELAX_TOKEN_SCOPE"] = "1" # Don't use in Web apps
scopes = ["https://spreadsheets.google.com/feeds/",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/analytics.readonly",
"https://www.googleapis.com/auth/webmasters.readonly",
"https://www.googleapis.com/auth/yt-analytics.readonly",
"https://www.googleapis.com/auth/youtube.readonly"]
client_config = {
"installed": {
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob"],
"client_id": client_id,
"client_secret": client_secret
}
}
flow = InstalledAppFlow.from_client_config(client_config, scopes)
credentials = flow.run_console()
credentials.access_token = credentials.token
with open("credentials.pickle", "wb") as output_file:
pickle.dump(credentials, output_file)
return credentials
示例4: main
# 需要导入模块: from google_auth_oauthlib.flow import InstalledAppFlow [as 别名]
# 或者: from google_auth_oauthlib.flow.InstalledAppFlow import from_client_config [as 别名]
def main(client_id, client_secret, scopes):
"""Retrieve and display the access and refresh token."""
client_config = ClientConfigBuilder(
client_type=ClientConfigBuilder.CLIENT_TYPE_WEB, client_id=client_id,
client_secret=client_secret)
flow = InstalledAppFlow.from_client_config(
client_config.Build(), scopes=scopes)
# Note that from_client_config will not produce a flow with the
# redirect_uris (if any) set in the client_config. This must be set
# separately.
flow.redirect_uri = _REDIRECT_URI
auth_url, _ = flow.authorization_url(prompt='consent')
print('Log into the Google Account you use to access your AdWords account '
'and go to the following URL: \n%s\n' % auth_url)
print('After approving the token enter the verification code (if specified).')
code = input('Code: ').strip()
try:
flow.fetch_token(code=code)
except InvalidGrantError as ex:
print('Authentication has failed: %s' % ex)
sys.exit(1)
print('Access token: %s' % flow.credentials.token)
print('Refresh token: %s' % flow.credentials.refresh_token)
示例5: main
# 需要导入模块: from google_auth_oauthlib.flow import InstalledAppFlow [as 别名]
# 或者: from google_auth_oauthlib.flow.InstalledAppFlow import from_client_config [as 别名]
def main(client_id, client_secret, scopes):
"""Retrieve and display the access and refresh token."""
client_config = ClientConfigBuilder(
client_type=ClientConfigBuilder.CLIENT_TYPE_WEB, client_id=client_id,
client_secret=client_secret)
flow = InstalledAppFlow.from_client_config(
client_config.Build(), scopes=scopes)
# Note that from_client_config will not produce a flow with the
# redirect_uris (if any) set in the client_config. This must be set
# separately.
flow.redirect_uri = _REDIRECT_URI
auth_url, _ = flow.authorization_url(prompt='consent')
print('Log into the Google Account you use to access your Ad Manager account'
'and go to the following URL: \n%s\n' % (auth_url))
print('After approving the token enter the verification code (if specified).')
code = input('Code: ').strip()
try:
flow.fetch_token(code=code)
except InvalidGrantError as ex:
print('Authentication has failed: %s' % ex)
sys.exit(1)
print('Access token: %s' % flow.credentials.token)
print('Refresh token: %s' % flow.credentials.refresh_token)