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


Python http.BatchHttpRequest方法代码示例

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


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

示例1: __init__

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import BatchHttpRequest [as 别名]
def __init__(self, callback=None, batch_uri=None):
    """Constructor for a BatchHttpRequest.

    Args:
      callback: callable, A callback to be called for each response, of the
        form callback(id, response, exception). The first parameter is the
        request id, and the second is the deserialized response object. The
        third is an apiclient.errors.HttpError exception object if an HTTP error
        occurred while processing the request, or None if no error occurred.
      batch_uri: string, URI to send batch requests to.
    """
    if batch_uri is None:
      batch_uri = 'https://www.googleapis.com/batch'
    self._batch_uri = batch_uri

    # Global callback to be called for each individual response in the batch.
    self._callback = callback

    # A map from id to request.
    self._requests = {}

    # A map from id to callback.
    self._callbacks = {}

    # List of request ids, in the order in which they were added.
    self._order = []

    # The last auto generated id.
    self._last_auto_id = 0

    # Unique ID on which to base the Content-ID headers.
    self._base_id = None

    # A map from request id to (httplib2.Response, content) response pairs
    self._responses = {}

    # A map of id(Credentials) that have been refreshed.
    self._refreshed_credentials = {} 
开发者ID:splunk,项目名称:splunk-ref-pas-code,代码行数:40,代码来源:http.py

示例2: execute

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import BatchHttpRequest [as 别名]
def execute(self):
    """Executes requests in the queue.

    Removes items from the queue, and adds them to a BatchHttpRequest object.
    Only removes up to set quota. and then calls the BatchHttPRequest object's
    execute method.
    """
    batch = BatchHttpRequest(callback=self.call_back)
    for _ in range(self.quota):
      if self.queue.qsize() == 0:
        break
      request, request_id = self.queue.get()
      batch.add(request, request_id=request_id)

    batch.execute(http=httplib2.Http()) 
开发者ID:googleanalytics,项目名称:api-samples,代码行数:17,代码来源:batchqueue.py

示例3: add_users

# 需要导入模块: from apiclient import http [as 别名]
# 或者: from apiclient.http import BatchHttpRequest [as 别名]
def add_users(users, permissions):
  """Adds users to every view (profile) with the given permissions.

  Args:
    users: A list of user email addresses.
    permissions: A list of user permissions.
  Note: this code assumes you have MANAGE_USERS level permissions
  to each profile and an authorized Google Analytics service object.
  """

  # Get the a full set of account summaries.
  account_summaries = analytics.management().accountSummaries().list().execute()

  # Loop through each account.
  for account in account_summaries.get('items', []):
    account_id = account.get('id')

    # Loop through each user.
    for user in users:
      # Create the BatchHttpRequest object.
      batch = BatchHttpRequest(callback=call_back)

      # Loop through each property.
      for property_summary in account.get('webProperties', []):
        property_id = property_summary.get('id')

        # Loop through each view (profile).
        for view in property_summary.get('profiles', []):
          view_id = view.get('id')

          # Construct the Profile User Link.
          link = analytics.management().profileUserLinks().insert(
              accountId=account_id,
              webPropertyId=property_id,
              profileId=view_id,
              body={
                  'permissions': {
                      'local': permissions
                  },
                  'userRef': {
                      'email': user
                  }
              }
          )
          batch.add(link)

      # Execute the batch request for each user.
      batch.execute() 
开发者ID:googleanalytics,项目名称:api-samples,代码行数:50,代码来源:permissions.py


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