當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。