How to use the googleads.ad_manager.StatementBuilder 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 kmjennison / dfp-prebid-setup / tests_integration / helpers / archive_order_by_name.py View on Github external
def archive_order_by_name(order_name):
  """
  Archives an order by name in DFP.

  Args:
    order_name (str): the name of the DFP order to archive
  Returns:
    None
  """
  client = get_client()
  order_service = client.GetService('OrderService', version='v201908')

  statement = (ad_manager.StatementBuilder()
    .Where('name = :name')
    .WithBindVariable('name', order_name))
  response = order_service.performOrderAction(
    {'xsi_type': 'ArchiveOrders'},
    statement.ToStatement())
github googleads / googleads-python-lib / examples / ad_manager / v201905 / custom_targeting_service / update_custom_targeting_keys.py View on Github external
def main(client, key_id):
  # Initialize appropriate service.
  custom_targeting_service = client.GetService(
      'CustomTargetingService', version='v201905')

  statement = (ad_manager.StatementBuilder(version='v201905')
               .Where('id = :keyId')
               .WithBindVariable('keyId', int(key_id))
               .Limit(1))

  # Get custom targeting keys by statement.
  response = custom_targeting_service.getCustomTargetingKeysByStatement(
      statement.ToStatement())

  # Update each local custom targeting key object by changing its display name.
  if 'results' in response and len(response['results']):
    updated_keys = []
    for key in response['results']:
      if not key['displayName']:
        key['displayName'] = key['name']
      key['displayName'] += ' (Deprecated)'
      updated_keys.append(key)
github googleads / googleads-python-lib / examples / ad_manager / v201808 / contact_service / update_contacts.py View on Github external
def main(client, contact_id):
  # Initialize appropriate service.
  contact_service = client.GetService('ContactService', version='v201808')

  # Create statement object to select the single contact by ID.
  statement = (ad_manager.StatementBuilder(version='v201808')
               .Where('id = :id')
               .WithBindVariable('id', long(contact_id))
               .Limit(1))

  # Get contacts by statement.
  response = contact_service.getContactsByStatement(
      statement.ToStatement())

  if 'results' in response and len(response['results']):
    updated_contacts = []
    for contact in response['results']:
      contact['address'] = '123 New Street, New York, NY, 10011'
      updated_contacts.append(contact)

    # Update the contact on the server.
    contacts = contact_service.updateContacts(updated_contacts)
github googleads / googleads-python-lib / examples / ad_manager / v201905 / inventory_service / archive_ad_units.py View on Github external
def main(client, parent_id):
  # Initialize appropriate service.
  inventory_service = client.GetService('InventoryService', version='v201905')

  # Create a query to select ad units under the parent ad unit and the parent ad
  # unit.
  statement = (ad_manager.StatementBuilder(version='v201905')
               .Where('parentId = :parentId or id = :parentId')
               .WithBindVariable('parentId', int(parent_id)))

  ad_units_archived = 0

  # Get ad units by statement.
  while True:
    response = inventory_service.getAdUnitsByStatement(
        statement.ToStatement())
    if 'results' in response and len(response['results']):
      for ad_unit in response['results']:
        print('Ad unit with ID "%s" and name "%s" will be archived.'
              % (ad_unit['id'], ad_unit['name']))
      # Perform action.
      result = inventory_service.performAdUnitAction(
          {'xsi_type': 'ArchiveAdUnits'}, statement.ToStatement())
github googleads / googleads-python-lib / examples / ad_manager / v201902 / base_rate_service / get_base_rates_for_rate_card.py View on Github external
def main(client, rate_card_id):
  # Initialize appropriate service.
  base_rate_service = client.GetService('BaseRateService', version='v201902')
  # Create a statement to select base rates.
  statement = (ad_manager.StatementBuilder(version='v201902')
               .Where('rateCardId = :rateCardId')
               .WithBindVariable('rateCardId', rate_card_id))

  # Retrieve a small amount of base rates at a time, paging
  # through until all base rates have been retrieved.
  while True:
    response = base_rate_service.getBaseRatesByStatement(statement.ToStatement(
    ))
    if 'results' in response and len(response['results']):
      for base_rate in response['results']:
        # Print out some information for each base rate.
        print('Base rate with ID "%d", type "%s", and rate card ID "%d" was '
              'found.\n' %
              (base_rate['id'], ad_manager.AdManagerClassType(base_rate),
               base_rate['rateCardId']))
      statement.offset += statement.limit
github googleads / googleads-python-lib / examples / ad_manager / v201905 / placement_service / get_active_placements.py View on Github external
def main(client):
  # Initialize appropriate service.
  placement_service = client.GetService('PlacementService', version='v201905')
  # Create a statement to select placements.
  statement = (ad_manager.StatementBuilder(version='v201905')
               .Where('status = :status')
               .WithBindVariable('status', 'ACTIVE'))

  # Retrieve a small amount of placements at a time, paging
  # through until all placements have been retrieved.
  while True:
    response = placement_service.getPlacementsByStatement(statement.ToStatement(
    ))
    if 'results' in response and len(response['results']):
      for placement in response['results']:
        # Print out some information for each placement.
        print('Placement with ID "%d" and name "%s" was found.\n' %
              (placement['id'], placement['name']))
      statement.offset += statement.limit
    else:
      break
github googleads / googleads-python-lib / examples / ad_manager / v201808 / placement_service / get_active_placements.py View on Github external
def main(client):
  # Initialize appropriate service.
  placement_service = client.GetService('PlacementService', version='v201808')
  # Create a statement to select placements.
  statement = (ad_manager.StatementBuilder(version='v201808')
               .Where('status = :status')
               .WithBindVariable('status', 'ACTIVE'))

  # Retrieve a small amount of placements at a time, paging
  # through until all placements have been retrieved.
  while True:
    response = placement_service.getPlacementsByStatement(statement.ToStatement(
    ))
    if 'results' in response and len(response['results']):
      for placement in response['results']:
        # Print out some information for each placement.
        print('Placement with ID "%d" and name "%s" was found.\n' %
              (placement['id'], placement['name']))
      statement.offset += statement.limit
    else:
      break
github googleads / googleads-python-lib / examples / ad_manager / v201808 / product_service / get_products_for_product_template.py View on Github external
def main(client, product_template_id):
  # Initialize appropriate service.
  product_service = client.GetService('ProductService', version='v201808')

  # Create a statement to select products.
  statement = (ad_manager.StatementBuilder(version='v201808')
               .Where('productTemplateId = :productTemplateId')
               .WithBindVariable('productTemplateId', product_template_id))

  # 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 and len(response['results']):
      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 += statement.limit
    else:
      break
github googleads / googleads-python-lib / examples / ad_manager / v201905 / creative_template_service / get_system_defined_creative_templates.py View on Github external
def main(client):
  # Initialize appropriate service.
  creative_template_service = client.GetService(
      'CreativeTemplateService', version='v201905')
  # Create a statement to select creative templates.
  statement = (ad_manager.StatementBuilder(version='v201905')
               .Where('type = :type')
               .WithBindVariable('type', 'SYSTEM_DEFINED'))

  # Retrieve a small amount of creative templates at a time, paging
  # through until all creative templates have been retrieved.
  while True:
    response = creative_template_service.getCreativeTemplatesByStatement(
        statement.ToStatement())
    if 'results' in response and len(response['results']):
      for creative_template in response['results']:
        # Print out some information for each creative template.
        print('Creative template with ID "%d" and name "%s" was found.\n' %
              (creative_template['id'], creative_template['name']))
      statement.offset += statement.limit
    else:
      break
github googleads / googleads-python-lib / examples / ad_manager / v201908 / custom_targeting_service / get_all_custom_targeting_keys_and_values.py View on Github external
def main(client):
  # Initialize appropriate service.
  custom_targeting_service = client.GetService(
      'CustomTargetingService', version='v201908')

  # Create statement to get all targeting keys.
  targeting_key_statement = ad_manager.StatementBuilder(version='v201908')

  all_keys = []

  # Get custom targeting keys by statement.
  while True:
    response = custom_targeting_service.getCustomTargetingKeysByStatement(
        targeting_key_statement.ToStatement())
    if 'results' in response and len(response['results']):
      all_keys.extend(response['results'])
      targeting_key_statement.offset += targeting_key_statement.limit
    else:
      break

  if all_keys:
    # Create a statement to select custom targeting values.
    statement = (ad_manager.StatementBuilder(version='v201908')