当前位置: 首页>>代码示例>>Python>>正文


Python InstalledAppFlow.from_client_config方法代码示例

本文整理汇总了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 
开发者ID:google,项目名称:starthinker,代码行数:25,代码来源:wrapper.py

示例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) 
开发者ID:s3ql,项目名称:s3ql,代码行数:27,代码来源:oauth_client.py

示例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 
开发者ID:miklevin,项目名称:Pipulate,代码行数:28,代码来源:__init__.py

示例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) 
开发者ID:googleads,项目名称:googleads-python-lib,代码行数:30,代码来源:generate_refresh_token.py

示例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) 
开发者ID:googleads,项目名称:googleads-python-lib,代码行数:30,代码来源:generate_refresh_token.py


注:本文中的google_auth_oauthlib.flow.InstalledAppFlow.from_client_config方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。