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


Python discovery.build_from_document方法代码示例

本文整理汇总了Python中googleapiclient.discovery.build_from_document方法的典型用法代码示例。如果您正苦于以下问题:Python discovery.build_from_document方法的具体用法?Python discovery.build_from_document怎么用?Python discovery.build_from_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在googleapiclient.discovery的用法示例。


在下文中一共展示了discovery.build_from_document方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_conn

# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build_from_document [as 别名]
def get_conn(self):
        """
        Retrieves the connection to Cloud Firestore.

        :return: Google Cloud Firestore services object.
        """
        if not self._conn:
            http_authorized = self._authorize()
            # We cannot use an Authorized Client to retrieve discovery document due to an error in the API.
            # When the authorized customer will send a request to the address below
            # https://www.googleapis.com/discovery/v1/apis/firestore/v1/rest
            # then it will get the message below:
            # > Request contains an invalid argument.
            # At the same time, the Non-Authorized Client has no problems.
            non_authorized_conn = build("firestore", self.api_version, cache_discovery=False)
            self._conn = build_from_document(
                non_authorized_conn._rootDesc,  # pylint: disable=protected-access
                http=http_authorized
            )
        return self._conn 
开发者ID:apache,项目名称:airflow,代码行数:22,代码来源:firestore.py

示例2: get_service

# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build_from_document [as 别名]
def get_service(api='gmail', version='v1', auth='service', scopes=None, uri_file=None):
  global DISCOVERY_CACHE 

  key = api + version + auth + str(threading.current_thread().ident)

  if key not in DISCOVERY_CACHE:
    credentials = get_credentials(auth)
    if uri_file:
      uri_file = uri_file.strip()
      if uri_file.startswith('{'):
        DISCOVERY_CACHE[key] = discovery.build_from_document(uri_file, credentials=credentials)
      else:
        with open(uri_file, 'r') as cache_file:
          DISCOVERY_CACHE[key] = discovery.build_from_document(cache_file.read(), credentials=credentials)
    else:
      DISCOVERY_CACHE[key] = discovery.build(api, version, credentials=credentials)

  return DISCOVERY_CACHE[key] 
开发者ID:google,项目名称:starthinker,代码行数:20,代码来源:__init__.py

示例3: _build_service_from_document

# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build_from_document [as 别名]
def _build_service_from_document(credentials, document_path):
    """Builds an API client from a local discovery document

    Args:
        credentials (OAuth2Credentials): Credentials that will be used to
            authenticate the API calls.
        document_path (str): The local path of the discovery document

    Returns:
        object: A Resource object with methods for interacting with the service.
    """
    with open(document_path, 'r') as f:
        discovery_data = json.load(f)

    return discovery.build_from_document(
        service=discovery_data,
        credentials=credentials
    )


# pylint: disable=too-many-instance-attributes 
开发者ID:forseti-security,项目名称:forseti-security,代码行数:23,代码来源:_base_repository.py

示例4: get_authenticated_service

# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build_from_document [as 别名]
def get_authenticated_service(args, credentials_folder):

    client_secrets_file = credentials_folder + "client_secrets.json"

    youtube_read_write_ssl_scope = "https://www.googleapis.com/auth/youtube.force-ssl"
    youtube_api_service_name = "youtube"
    youtube_api_version = "v3"

    missing_clients_secrets_message = """
    WARNING: Please configure OAuth 2.0

    To make this sample run you will need to populate the client_secrets.json file
    found at:
       %s
    with information from the APIs Console
    https://developers.google.com/console

    For more information about the client_secrets.json file format, please visit:
    https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
    """ % os.path.abspath(os.path.join(os.path.dirname(__file__),
                                       client_secrets_file))

    flow = flow_from_clientsecrets(client_secrets_file,
                                   scope=youtube_read_write_ssl_scope,
                                   message=missing_clients_secrets_message)

    storage = Storage(credentials_folder + "reveal-stored-oauth2.json")
    credentials = storage.get()

    if credentials is None or credentials.invalid:
        credentials = run_flow(flow, storage, args)

    # Trusted testers can download this discovery document from the developers page
    #  and it should be in the same directory with the code.
    with open(credentials_folder + "youtube-v3-discoverydocument.json", "r") as f:
        doc = f.read()
        return build_from_document(doc, credentials=credentials) 
开发者ID:MKLab-ITI,项目名称:news-popularity-prediction,代码行数:39,代码来源:auth_new.py


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