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

  values = [{
      'key': 'keyId',
      'value': {
          'xsi_type': 'NumberValue',
          'value': key_id
      }
  }]
  query = 'WHERE customTargetingKeyId = :keyId'
  statement = dfp.FilterStatement(query, values)

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

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