def main(client):
  # Initialize appropriate service.
  custom_targeting_service = client.GetService(
      'CustomTargetingService', version='v201511')

  values = [{
      'key': 'type',
      'value': {
          'xsi_type': 'TextValue',
          'value': 'PREDEFINED'
      }
  }]
  query = 'WHERE type = :type'
  statement = dfp.FilterStatement(query, values)

  # Get custom targeting keys by statement.
  while True:
    response = custom_targeting_service.getCustomTargetingKeysByStatement(
        statement.ToStatement())
    if 'results' in response:
      # Display results.
      for key in response['results']:
        print ('Custom targeting key with id \'%s\', name \'%s\', display name '
               '\'%s\', and type \'%s\' was found.'
               % (key['id'], key['name'], key['displayName'], key['type']))
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  print '\nNumber of results found: %s' % response['totalResultSetSize']
dataset/ETHPy150Open googleads/googleads-python-lib/examples/dfp/v201511/custom_targeting_service/get_custom_targeting_keys_by_statement.py/main/original