How to use the googleads.dfp.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 googleads / googleads-python-lib / examples / dfp / v201711 / product_service / publish_programmatic_products_to_marketplace.py View on Github external
def main(client, product_id):
  # Initialize appropriate service.
  product_service = client.GetService('ProductService', version='v201711')

  # Create query.
  statement = (dfp.StatementBuilder()
               .Where('id = :id')
               .WithBindVariable('id', long(product_id))
               .Limit(1))

  products_published = 0

  # Get products by statement.
  while True:
    response = product_service.getProductsByStatement(
        statement.ToStatement())
    if 'results' in response:
      for product in response['results']:
        print ('Product with id "%s" and name "%s" will be '
               'published.' % (product['id'],
                               product['name']))
github googleads / googleads-python-lib / examples / dfp / v201802 / line_item_service / update_line_items.py View on Github external
def main(client, order_id):
  # Initialize appropriate service.
  line_item_service = client.GetService('LineItemService', version='v201802')

  # Create statement object to only select line items with even delivery rates.

  statement = (dfp.StatementBuilder()
               .Where(('deliveryRateType = :deliveryRateType AND '
                       'orderId = :orderId'))
               .WithBindVariable('orderId', long(order_id))
               .WithBindVariable('deliveryRateType', 'EVENLY')
               .Limit(500))

  # Get line items by statement.
  response = line_item_service.getLineItemsByStatement(
      statement.ToStatement())

  if 'results' in response and len(response['results']):
    # Update each local line item by changing its delivery rate type.
    updated_line_items = []
    for line_item in response['results']:
      if not line_item['isArchived']:
        line_item['deliveryRateType'] = 'AS_FAST_AS_POSSIBLE'
github googleads / googleads-python-lib / examples / dfp / v201711 / workflow_request_service / approve_workflow_approval_requests.py View on Github external
def main(client, proposal_id):
  # Initialize appropriate service.
  workflow_request_service = client.GetService('WorkflowRequestService',
                                               version='v201711')

  # Create a filter statement.
  statement = (dfp.StatementBuilder()
               .Where(('entityId = :entityId and entityType = :entityType '
                       'and type = :type'))
               .WithBindVariable('entityId', proposal_id)
               .WithBindVariable('entityType', 'PROPOSAL')
               .WithBindVariable('type', 'WORKFLOW_APPROVAL_REQUEST'))
  workflow_approval_requests_approved = 0

  # Get workflow approval requests by statement.
  while True:
    response = workflow_request_service.getWorkflowRequestsByStatement(
        statement.ToStatement())
    if 'results' in response and len(response['results']):
      # Display results.
      for workflow_approval_request in response['results']:
        print ('Workflow approval request with id "%s" will be'
               ' approved.' % workflow_approval_request['id'])
github googleads / googleads-python-lib / examples / dfp / v201711 / reconciliation_line_item_report_service / get_reconciliation_line_item_reports_for_reconciliation_report.py View on Github external
def main(client):
  # Initialize appropriate service.
  reconciliation_line_item_report_service = (client.GetService(
      'ReconciliationLineItemReportService', version='v201711'))

  # Create a statement to select reconciliation line item reports.
  statement = (dfp.StatementBuilder()
               .Where(('reconciliationReportId = :reconciliationReportId AND '
                       'lineItemId != :lineItemId'))
               .OrderBy('lineItemId', ascending=True)
               .WithBindVariable('reconciliationReportId',
                                 RECONCILIATION_REPORT_ID)
               .WithBindVariable('lineItemId', 0))

  # Retrieve a small amount of reconciliation line item reports at a time,
  # paging through until all reconciliation line item reports have been
  # retrieved.
  result_set_size = 0
  should_continue = True

  while should_continue:
    page = (reconciliation_line_item_report_service
            .getReconciliationLineItemReportsByStatement(
github googleads / googleads-python-lib / examples / dfp / v201802 / custom_field_service / get_custom_fields_for_line_items.py View on Github external
def main(client):
  # Initialize appropriate service.
  custom_field_service = client.GetService(
      'CustomFieldService', version='v201802')
  # Create a statement to select custom fields.
  statement = (dfp.StatementBuilder()
               .Where('entityType = :entityType')
               .WithBindVariable('entityType', 'LINE_ITEM'))

  # Retrieve a small amount of custom fields at a time, paging
  # through until all custom fields have been retrieved.
  while True:
    response = custom_field_service.getCustomFieldsByStatement(
        statement.ToStatement())
    if 'results' in response and len(response['results']):
      for custom_field in response['results']:
        # Print out some information for each custom field.
        print('Custom field with ID "%d" and name "%s" was found.\n' %
              (custom_field['id'], custom_field['name']))
      statement.offset += statement.limit
    else:
      break
github googleads / googleads-python-lib / examples / dfp / v201805 / premium_rate_service / get_all_premium_rates.py View on Github external
def main(client):
  # Initialize appropriate service.
  premium_rate_service = client.GetService(
      'PremiumRateService', version='v201805')

  # Create a statement to select premium rates.
  statement = dfp.StatementBuilder()

  # Retrieve a small amount of premium rates at a time, paging
  # through until all premium rates have been retrieved.
  while True:
    response = premium_rate_service.getPremiumRatesByStatement(
        statement.ToStatement())
    if 'results' in response and len(response['results']):
      for premium_rate in response['results']:
        # Print out some information for each premium rate.
        print('Premium rate with ID "%d", premium feature "%s", and rate card '
              'id "%d" was found.\n' % (premium_rate['id'],
                                        dfp.DfpClassType(premium_rate),
                                        premium_rate['rateCardId']))
      statement.offset += statement.limit
    else:
      break
github googleads / googleads-python-lib / examples / dfp / v201805 / audience_segment_service / get_first_party_audience_segments.py View on Github external
def main(client):
  # Initialize appropriate service.
  audience_segment_service = client.GetService(
      'AudienceSegmentService', version='v201805')
  # Create a statement to select audience segments.
  statement = (dfp.StatementBuilder()
               .Where('type = :type')
               .WithBindVariable('type', 'FIRST_PARTY'))

  # Retrieve a small amount of audience segments at a time, paging
  # through until all audience segments have been retrieved.
  while True:
    response = audience_segment_service.getAudienceSegmentsByStatement(
        statement.ToStatement())
    if 'results' in response and len(response['results']):
      for audience_segment in response['results']:
        # Print out some information for each audience segment.
        print('Audience segment with ID "%d", name "%s", and size "%d" was '
              'found.\n' % (audience_segment['id'], audience_segment['name'],
                            audience_segment['size']))
      statement.offset += statement.limit
    else:
github googleads / googleads-python-lib / examples / dfp / v201705 / user_team_association_service / get_all_user_team_associations.py View on Github external
def main(client):
  # Initialize appropriate service.
  user_team_association_service = client.GetService(
      'UserTeamAssociationService', version='v201705')

  # Create a statement to select user team associations.
  statement = dfp.StatementBuilder()

  # Retrieve a small amount of user team associations at a time, paging
  # through until all user team associations have been retrieved.
  while True:
    response = user_team_association_service.getUserTeamAssociationsByStatement(
        statement.ToStatement())
    if 'results' in response:
      for user_team_association in response['results']:
        # Print out some information for each user team association.
        print('User team association with team id "%d" and user id "%d" was '
              'found.\n' % (user_team_association['teamId'],
                            user_team_association['userId']))
      statement.offset += statement.limit
    else:
      break
github googleads / googleads-python-lib / examples / dfp / v201802 / user_team_association_service / update_user_team_associations.py View on Github external
def main(client, user_id):
  # Initialize appropriate service.
  user_team_association_service = client.GetService(
      'UserTeamAssociationService', version='v201802')

  # Create filter text to select user team associations by the user ID.
  statement = (dfp.StatementBuilder()
               .Where('userId = :userId')
               .WithBindVariable('userId', long(user_id)))

  # Get user team associations by statement.
  response = user_team_association_service.getUserTeamAssociationsByStatement(
      statement.ToStatement())

  if 'results' in response and len(response['results']):
    updated_user_team_associations = []
    # Update each local user team association to read only access.
    for user_team_association in response['results']:
      user_team_association['overriddenTeamAccessType'] = 'READ_ONLY'
      updated_user_team_associations.append(user_team_association)

    # Update user team associations on the server.
    user_team_associations = (
github googleads / googleads-python-lib / examples / dfp / v201805 / rate_card_service / get_marketplace_rate_cards.py View on Github external
def main(client):
  # Initialize appropriate service.
  rate_card_service = client.GetService('RateCardService', version='v201805')
  # Create a statement to select rate cards.
  statement = (dfp.StatementBuilder()
               .Where('forMarketplace = :forMarketplace')
               .WithBindVariable('forMarketplace', True))

  # Retrieve a small amount of rate cards at a time, paging
  # through until all rate cards have been retrieved.
  while True:
    response = rate_card_service.getRateCardsByStatement(statement.ToStatement(
    ))
    if 'results' in response and len(response['results']):
      for rate_card in response['results']:
        # Print out some information for each rate card.
        print(
            'Rate card with ID "%d", name "%s", and currency code "%s" was '
            'found.\n'
            % (rate_card['id'], rate_card['name'], rate_card['currencyCode']))
      statement.offset += statement.limit