How to use the googleads.dfp.SUGGESTED_PAGE_LIMIT function in googleads

To help you get started, we’ve selected a few googleads examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleads / googleads-python-lib / examples / dfp / v201708 / report_service / run_report_with_custom_fields.py View on Github external
.WithBindVariable('orderId', long(order_id)))

  # Collect all line item custom field IDs for an order.
  custom_field_ids = set()

  # Get users by statement.
  while True:
    response = line_item_service.getLineItemsByStatement(
        statement.ToStatement())
    if 'results' in response:
      # Get custom field IDs from the line items of an order.
      for line_item in response['results']:
        if 'customFieldValues' in line_item:
          for custom_field_value in line_item['customFieldValues']:
            custom_field_ids.add(custom_field_value['customFieldId'])
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  # Modify statement for reports
  statement.limit = None
  statement.offset = None
  statement.Where('ORDER_ID = :orderId')

  # Create report job.
  report_job = {
      'reportQuery': {
          'dimensions': ['LINE_ITEM_ID', 'LINE_ITEM_NAME'],
          'statement': statement.ToStatement(),
          'columns': ['AD_SERVER_IMPRESSIONS'],
          'dateRangeType': 'LAST_MONTH',
          'customFieldIds': list(custom_field_ids)
github googleads / googleads-python-lib / examples / dfp / v201511 / placement_service / create_placements.py View on Github external
if 'results' in response:
      # Separate the ad units by size.
      for ad_unit in response['results']:
        if 'adUnitSizes' in ad_unit:
          for ad_unit_size in ad_unit['adUnitSizes']:
            size = ad_unit_size['size']
            if size['width'] == '300' and size['height'] == '250':
              medium_rectangle_ad_unit_placement['targetedAdUnitIds'].append(
                  ad_unit['id'])
            elif size['width'] == '120' and size['height'] == '600':
              skyscraper_ad_unit_placement['targetedAdUnitIds'].append(
                  ad_unit['id'])
            elif size['width'] == '468' and size['height'] == '60':
              banner_ad_unit_placement['targetedAdUnitIds'].append(
                  ad_unit['id'])
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  # Only create placements with one or more ad unit.
  if medium_rectangle_ad_unit_placement['targetedAdUnitIds']:
    placement_list.append(medium_rectangle_ad_unit_placement)

  if skyscraper_ad_unit_placement['targetedAdUnitIds']:
    placement_list.append(skyscraper_ad_unit_placement)

  if banner_ad_unit_placement['targetedAdUnitIds']:
    placement_list.append(banner_ad_unit_placement)

  # Add placements.
  placements = placement_service.createPlacements(placement_list)
github googleads / googleads-python-lib / examples / dfp / v201611 / workflow_request_service / get_workflow_approval_requests.py View on Github external
# Create a statement to select workflow requests.
  statement = dfp.FilterStatement(query, values)

  # Retrieve a small amount of workflow requests at a time, paging
  # through until all workflow requests have been retrieved.
  while True:
    response = workflow_request_service.getWorkflowRequestsByStatement(
        statement.ToStatement())
    if 'results' in response:
      for workflow_request in response['results']:
        # Print out some information for each workflow request.
        print('Workflow request with ID "%d", entity type "%s", and entity ID '
              '"%d" was found.\n' % (workflow_request['id'],
                                     workflow_request['entityType'],
                                     workflow_request['entityId']))
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201511 / custom_field_service / get_all_line_item_custom_fields.py View on Github external
}]
  query = 'WHERE entityType = :entityType'

  # Create a filter statement.
  statement = dfp.FilterStatement(query, values)

  # Get custom fields by statement.
  while True:
    response = custom_field_service.getCustomFieldsByStatement(
        statement.ToStatement())
    if 'results' in response:
      # Display results.
      for custom_field in response['results']:
        print ('Custom field with ID \'%s\' and name \'%s\' was found.'
               % (custom_field['id'], custom_field['name']))
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201508 / content_service / get_content_by_category.py View on Github external
]
    content_query = 'WHERE status = :status'
    content_statement = dfp.FilterStatement(content_query, content_values)

    while True:
      # Get the content by statement and custom targeting value.
      response = content_service.getContentByStatementAndCustomTargetingValue(
          content_statement.ToStatement(),
          category_custom_targeting_value_id)
      if 'results' in response:
        # Display results.
        for content_item in response['results']:
          print ('Content with id \'%s\', name \'%s\', and status \'%s\' was '
                 'found.' % (content_item['id'], content_item['name'],
                             content_item['status']))
        content_statement.offset += dfp.SUGGESTED_PAGE_LIMIT
      else:
        break

    print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201602 / content_service / get_content_by_category.py View on Github external
]
    content_query = 'WHERE status = :status'
    content_statement = dfp.FilterStatement(content_query, content_values)

    while True:
      # Get the content by statement and custom targeting value.
      response = content_service.getContentByStatementAndCustomTargetingValue(
          content_statement.ToStatement(),
          category_custom_targeting_value_id)
      if 'results' in response:
        # Display results.
        for content_item in response['results']:
          print ('Content with id \'%s\', name \'%s\', and status \'%s\' was '
                 'found.' % (content_item['id'], content_item['name'],
                             content_item['status']))
        content_statement.offset += dfp.SUGGESTED_PAGE_LIMIT
      else:
        break

    print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201705 / product_service / get_products_for_product_template.py View on Github external
'value': product_template_id
       }},
  ]
  # Create a statement to select products.
  statement = dfp.FilterStatement(query, values)

  # Retrieve a small amount of products at a time, paging
  # through until all products have been retrieved.
  while True:
    response = product_service.getProductsByStatement(statement.ToStatement())
    if 'results' in response:
      for product in response['results']:
        # Print out some information for each product.
        print('Product with ID "%d" and name "%s" was found.\n' %
              (product['id'], product['name']))
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201605 / inventory_service / get_ad_unit_hierarchy.py View on Github external
def main(client):
  # Initialize appropriate service.
  inventory_service = client.GetService('InventoryService', version='v201605')
  statement = dfp.FilterStatement()

  all_ad_units = []
  # Get ad units by statement.
  while True:
    response = inventory_service.getAdUnitsByStatement(
        statement.ToStatement())
    if 'results' in response:
      all_ad_units.extend(response['results'])
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  # Find the root ad unit. root_ad_unit can also be set to child unit to only
  # build and display a portion of the tree.
  query = 'WHERE parentId IS NULL'
  root_statement = dfp.FilterStatement(query)
  response = inventory_service.getAdUnitsByStatement(
      root_statement.ToStatement())
  root_ad_unit = response['results'][0]

  if root_ad_unit:
    BuildAndDisplayAdUnitTree(root_ad_unit, all_ad_units)
  else:
    print 'Could not build tree. No root ad unit found.'
github googleads / googleads-python-lib / examples / dfp / v201511 / exchange_rate_service / get_exchange_rates_by_currency_code.py View on Github external
# Get rate cards by statement.
  while True:
    response = exchange_rate_service.getExchangeRatesByStatement(
        statement.ToStatement())
    if 'results' in response:
      # Display results.
      for exchange_rate in response['results']:
        print ('Exchange rate with id \'%s,\' currency code \'%s,\' '
               'direction \'%s,\' and exchange rate \'%.2f\' '
               'was found.' % (exchange_rate['id'],
                               exchange_rate['currencyCode'],
                               exchange_rate['direction'],
                               (float(exchange_rate['exchangeRate']) /
                                10000000000)))
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
github googleads / googleads-python-lib / examples / dfp / v201511 / rate_card_service / get_all_rate_cards.py View on Github external
rate_card_service = client.GetService('RateCardService', version='v201511')

  # Create a filter statement.
  statement = dfp.FilterStatement('ORDER BY id ASC')

  # Get rate cards by statement.
  while True:
    response = rate_card_service.getRateCardsByStatement(
        statement.ToStatement())
    if 'results' in response:
      # Display results.
      for rate_card in response['results']:
        print ('Rate card with id \'%s,\' name \'%s,\' and currency \'%s\' '
               'was found.' % (rate_card['id'], rate_card['name'],
                               rate_card['currencyCode']))
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']