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