def main(client):
  # Initialize appropriate service.
  content_service = client.GetService('ContentService', version='v201508')
  network_service = client.GetService('NetworkService', version='v201508')
  custom_targeting_service = client.GetService(
      'CustomTargetingService', version='v201508')

  # Get the network's content browse custom targeting key.
  network = network_service.getCurrentNetwork()
  key_id = network['contentBrowseCustomTargetingKeyId']

  # Create a statement to select the categories matching the name comedy.
  values = [
      {
          'key': 'contentBrowseCustomTargetingKeyId',
          'value': {
              'xsi_type': 'NumberValue',
              'value': key_id
          }
      },
      {
          'key': 'category',
          'value': {
              'xsi_type': 'TextValue',
              'value': 'comedy'
          }
      }
  ]
  category_filter_query = ('WHERE customTargetingKeyId = '
                           ':contentBrowseCustomTargetingKeyId and name = '
                           ':category')
  category_filter_statement = dfp.FilterStatement(
      category_filter_query, values, 1)

  # Get categories matching the filter statement.
  response = custom_targeting_service.getCustomTargetingValuesByStatement(
      category_filter_statement.ToStatement())

  # Get the custom targeting value ID for the comedy category.
  if 'results' in response:
    category_custom_targeting_value_id = (response['results']['id'])

    # Create a statement to select the active content.
    content_values = [
        {
            'key': 'status',
            'value': {
                'xsi_type': 'TextValue',
                'value': 'ACTIVE'
            }
        }
    ]
    content_query = 'WHERE status = :status'
    content_statement = dfp.FilterStatement(content_query, content_values)

    while True:
      # Get the content by statement and custom targeting value.
      response = content_service.getContentByStatementAndCustomTargetingValue(
          content_statement.ToStatement(),
          category_custom_targeting_value_id)
      if 'results' in response:
        # Display results.
        for content_item in response['results']:
          print ('Content with id \'%s\', name \'%s\', and status \'%s\' was '
                 'found.' % (content_item['id'], content_item['name'],
                             content_item['status']))
        content_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/content_service/get_content_by_category.py/main/original