How to use the googleads.ad_manager.AdManagerClassType 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 / ad_manager / v201808 / creative_service / copy_image_creatives.py View on Github external
# Get the creative.
  query_result = creative_service.getCreativesByStatement(
      statement.ToStatement())

  image_creative = query_result['results'][0]

  # Build the new creative, set id to None to create a copy.
  image_creative['id'] = None
  image_creative['name'] = 'Copy of %s' % image_creative['name']

  result = creative_service.createCreatives([image_creative])[0]
  print ('A creative with ID %d, name "%s", and type "%s" was created and '
         'can be previewed at: %s' % (result['id'],
                                      result['name'],
                                      ad_manager.AdManagerClassType(result),
                                      result['previewUrl']))
github googleads / googleads-python-lib / examples / ad_manager / v201908 / custom_field_service / set_line_item_custom_field_value.py View on Github external
if (old_custom_field_value['customFieldId'] !=
          custom_field_value['customFieldId']
          and old_custom_field_value['customFieldId'] !=
          drop_down_custom_field_value['customFieldId']):
        custom_field_values.append(old_custom_field_value)

    line_item['customFieldValues'] = custom_field_values

    # Update the line item on the server.
    line_items = line_item_service.updateLineItems([line_item])

    # Display results.
    for line_item in line_items:
      custom_field_value_strings = []
      for value in line_item['customFieldValues']:
        if ad_manager.AdManagerClassType(value) == 'CustomFieldValue':
          custom_field_value_string = (
              '{ID: "%s", value: "%s"}'
              % (value['customFieldId'], value['value']['value']))
        elif ad_manager.AdManagerClassType(value) == 'DropDownCustomFieldValue':
          custom_field_value_string = (
              '{ID: "%s", custom field option ID: "%s"}'
              % (value['customFieldId'], value['customFieldOptionId']))
        custom_field_value_strings.append(custom_field_value_string)
      print('Line item with ID "%s" set with custom field values %s.'
            % (line_item['id'], ','.join(custom_field_value_strings)))
  else:
    print('Line item or custom field not found.')
github googleads / googleads-python-lib / examples / ad_manager / v201908 / custom_field_service / set_line_item_custom_field_value.py View on Github external
custom_field_values.append(old_custom_field_value)

    line_item['customFieldValues'] = custom_field_values

    # Update the line item on the server.
    line_items = line_item_service.updateLineItems([line_item])

    # Display results.
    for line_item in line_items:
      custom_field_value_strings = []
      for value in line_item['customFieldValues']:
        if ad_manager.AdManagerClassType(value) == 'CustomFieldValue':
          custom_field_value_string = (
              '{ID: "%s", value: "%s"}'
              % (value['customFieldId'], value['value']['value']))
        elif ad_manager.AdManagerClassType(value) == 'DropDownCustomFieldValue':
          custom_field_value_string = (
              '{ID: "%s", custom field option ID: "%s"}'
              % (value['customFieldId'], value['customFieldOptionId']))
        custom_field_value_strings.append(custom_field_value_string)
      print('Line item with ID "%s" set with custom field values %s.'
            % (line_item['id'], ','.join(custom_field_value_strings)))
  else:
    print('Line item or custom field not found.')
github googleads / googleads-python-lib / examples / ad_manager / v201908 / publisher_query_language_service / get_recent_changes.py View on Github external
Returns:
    str a CSV writer friendly value formatted by Value.Type.
  """
  if 'value' in pql_value:
    field = pql_value['value']
  elif 'values' in pql_value:
    field = pql_value['values']
  else:
    field = None

  if field:
    if isinstance(field, list):
      return ','.join(['"%s"' % str(ConvertValueForCsv(single_field))
                       for single_field in field])
    else:
      class_type = ad_manager.AdManagerClassType(pql_value)

      if class_type == 'TextValue':
        return field.replace('"', '""').encode('UTF8')
      elif class_type == 'NumberValue':
        return float(field) if '.' in field else int(field)
      elif class_type == 'DateTimeValue':
        return ConvertDateTimeToOffset(field)
      elif class_type == 'DateValue':
        return date(int(field['date']['year']),
                    int(field['date']['month']),
                    int(field['date']['day'])).isoformat()
      else:
        return field
  else:
    return '-'
github googleads / googleads-python-lib / examples / ad_manager / v201911 / custom_field_service / set_line_item_custom_field_value.py View on Github external
if (old_custom_field_value['customFieldId'] !=
          custom_field_value['customFieldId']
          and old_custom_field_value['customFieldId'] !=
          drop_down_custom_field_value['customFieldId']):
        custom_field_values.append(old_custom_field_value)

    line_item['customFieldValues'] = custom_field_values

    # Update the line item on the server.
    line_items = line_item_service.updateLineItems([line_item])

    # Display results.
    for line_item in line_items:
      custom_field_value_strings = []
      for value in line_item['customFieldValues']:
        if ad_manager.AdManagerClassType(value) == 'CustomFieldValue':
          custom_field_value_string = (
              '{ID: "%s", value: "%s"}'
              % (value['customFieldId'], value['value']['value']))
        elif ad_manager.AdManagerClassType(value) == 'DropDownCustomFieldValue':
          custom_field_value_string = (
              '{ID: "%s", custom field option ID: "%s"}'
              % (value['customFieldId'], value['customFieldOptionId']))
        custom_field_value_strings.append(custom_field_value_string)
      print('Line item with ID "%s" set with custom field values %s.'
            % (line_item['id'], ','.join(custom_field_value_strings)))
  else:
    print('Line item or custom field not found.')
github googleads / googleads-python-lib / examples / ad_manager / v201905 / creative_service / create_custom_creative.py View on Github external
}
          }
      ],
      'htmlSnippet': html_snippet
  }

  # Call service to create the creative.
  creatives = creative_service.createCreatives([creative])

  # Display results.
  if creatives:
    creative = creatives[0]
    print('Template creative with id "%s", name "%s", and type "%s" was '
          'created and can be previewed at %s.'
          % (creative['id'], creative['name'],
              ad_manager.AdManagerClassType(creative), creative['previewUrl']))
github googleads / googleads-python-lib / examples / ad_manager / v201911 / creative_service / create_creatives.py View on Github external
'destinationUrl': 'http://google.com',
        'size': size,
        'primaryImageAsset': creative_asset
    }

    creatives.append(creative)

  # Add creatives.
  creatives = creative_service.createCreatives(creatives)

  # Display results.
  for creative in creatives:
    print('Image creative with id "%s", name "%s", and type "%s" was '
          'created and can be previewed at %s.'
          % (creative['id'], creative['name'],
              ad_manager.AdManagerClassType(creative), creative['previewUrl']))
github googleads / googleads-python-lib / examples / ad_manager / v201911 / publisher_query_language_service / get_recent_changes.py View on Github external
Returns:
    str a CSV writer friendly value formatted by Value.Type.
  """
  if 'value' in pql_value:
    field = pql_value['value']
  elif 'values' in pql_value:
    field = pql_value['values']
  else:
    field = None

  if field:
    if isinstance(field, list):
      return ','.join(['"%s"' % str(ConvertValueForCsv(single_field))
                       for single_field in field])
    else:
      class_type = ad_manager.AdManagerClassType(pql_value)

      if class_type == 'TextValue':
        return field.replace('"', '""').encode('UTF8')
      elif class_type == 'NumberValue':
        return float(field) if '.' in field else int(field)
      elif class_type == 'DateTimeValue':
        return ConvertDateTimeToOffset(field)
      elif class_type == 'DateValue':
        return date(int(field['date']['year']),
                    int(field['date']['month']),
                    int(field['date']['day'])).isoformat()
      else:
        return field
  else:
    return '-'