/** Returns the campaign feeds that use a particular feed for a particular placeholder type. */
  private static List<CampaignFeed> getCampaignFeeds(
      AdWordsServices adWordsServices, AdWordsSession session, Feed feed, int placeholderType)
      throws Exception {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService =
        adWordsServices.get(session, CampaignFeedServiceInterface.class);

    String query =
        String.format(
            "SELECT CampaignId, MatchingFunction, PlaceholderTypes WHERE Status = 'ENABLED' "
                + "AND FeedId = %d AND PlaceholderTypes CONTAINS_ANY [%d]",
            feed.getId(), placeholderType);

    List<CampaignFeed> campaignFeeds = Lists.newArrayList();
    int offset = 0;
    CampaignFeedPage campaignFeedPage;

    do {
      String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
      campaignFeedPage = campaignFeedService.query(pageQuery);
      if (campaignFeedPage.getEntries() != null) {
        campaignFeeds.addAll(Arrays.asList(campaignFeedPage.getEntries()));
      }
      offset += PAGE_SIZE;
    } while (offset < campaignFeedPage.getTotalNumEntries());

    return campaignFeeds;
  }
  /** Deletes a campaign feed. */
  private static CampaignFeed deleteCampaignFeed(
      AdWordsServices adWordsServices, AdWordsSession session, CampaignFeed campaignFeed)
      throws Exception {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService =
        adWordsServices.get(session, CampaignFeedServiceInterface.class);

    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.REMOVE);

    return campaignFeedService.mutate(new CampaignFeedOperation[] {operation}).getValue(0);
  }