/// <summary>
        /// Add legacy sitelinks to the sitelinks feed.
        /// </summary>
        /// <param name="feedItemService">The feed item service.</param>
        /// <param name="siteLinksFeed">The feed for adding sitelinks.</param>
        /// <param name="sitelinks">The list of legacy sitelinks to be added to the
        /// feed.</param>
        /// <returns>The list of feeditems that were added to the feed.</returns>
        private static List<long> createSiteLinkFeedItems(FeedItemService feedItemService,
        SiteLinksFeed siteLinksFeed, Sitelink[] sitelinks)
        {
            List<long> siteLinkFeedItemIds = new List<long>();

              // Create operation for adding each legacy sitelink to the sitelinks feed.
              List<FeedItemOperation> feedItemOperations = new List<FeedItemOperation>();

              foreach (Sitelink sitelink in sitelinks) {
            FeedItemOperation operation = newSiteLinkFeedItemAddOperation(
            siteLinksFeed, sitelink.displayText, sitelink.destinationUrl);
            feedItemOperations.Add(operation);
              }

              FeedItemReturnValue result = feedItemService.mutate(feedItemOperations.ToArray());

              // Retrieve the feed item ids.
              foreach (FeedItem item in result.value) {
            siteLinkFeedItemIds.Add(item.feedItemId);
              }
              return siteLinkFeedItemIds;
        }
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">Id of the camapign to which sitelinks are
        /// added.</param>
        public void Run(AdWordsUser user, long campaignId)
        {
            // Get the CampaignAdExtensionService.
              CampaignAdExtensionService campaignExtensionService =
              (CampaignAdExtensionService)user.GetService(AdWordsService.v201306.
              CampaignAdExtensionService);

              // Create the sitelinks.
              SitelinksExtension siteLinkExtension = new SitelinksExtension();

              Sitelink siteLink1 = new Sitelink();
              siteLink1.displayText = "Music";
              siteLink1.destinationUrl = "http://www.example.com/music";

              Sitelink siteLink2 = new Sitelink();
              siteLink2.displayText = "DVDs";
              siteLink2.destinationUrl = "http://www.example.com/dvds";

              Sitelink siteLink3 = new Sitelink();
              siteLink3.displayText = "New albums";
              siteLink3.destinationUrl = "http://www.example.com/albums/new";

              siteLinkExtension.sitelinks = new Sitelink[] {siteLink1, siteLink2, siteLink3};

              CampaignAdExtension campaignAdExtension = new CampaignAdExtension();
              campaignAdExtension.adExtension = siteLinkExtension;
              campaignAdExtension.campaignId = campaignId;

              // Create the operation.
              CampaignAdExtensionOperation operation = new CampaignAdExtensionOperation();
              operation.@operator = Operator.ADD;
              operation.operand = campaignAdExtension;

              try {
            // Create the sitelinks.
            CampaignAdExtensionReturnValue retVal =
            campaignExtensionService.mutate(new CampaignAdExtensionOperation[] {operation});

            // Display the results.
            if (retVal != null && retVal.value != null && retVal.value.Length > 0) {
              CampaignAdExtension campaignExtension = retVal.value[0];
              Console.WriteLine("Created a campaign ad extension with id = \"{0}\" and " +
              "status = \"{1}\"", campaignExtension.adExtension.id, campaignExtension.status);
              foreach (Sitelink siteLink in
              (campaignExtension.adExtension as SitelinksExtension).sitelinks) {
            Console.WriteLine("-- Site link text is \"{0}\" and destination url is {1}",
                siteLink.displayText, siteLink.destinationUrl);
              }
            } else {
              Console.WriteLine("No sitelinks were created.");
            }
              } catch (Exception ex) {
            throw new System.ApplicationException("Failed to add site links.", ex);
              }
        }
        /// <summary>
        /// Creates the legacy sitelinks.
        /// </summary>
        /// <param name="user">The AdWords user.</param>
        /// <param name="campaignId">The campaign id.</param>
        /// <returns>The list of legacy sitelinks.</returns>
        public Sitelink[] CreateLegacySitelinks(AdWordsUser user, long campaignId)
        {
            // Get the CampaignAdExtensionService.
              CampaignAdExtensionService campaignExtensionService =
              (CampaignAdExtensionService) user.GetService(AdWordsService.v201306.
              CampaignAdExtensionService);

              // Create the sitelinks.
              SitelinksExtension siteLinkExtension = new SitelinksExtension();

              Sitelink siteLink1 = new Sitelink();
              siteLink1.displayText = "Music";
              siteLink1.destinationUrl = "http://www.example.com/music";

              Sitelink siteLink2 = new Sitelink();
              siteLink2.displayText = "DVDs";
              siteLink2.destinationUrl = "http://www.example.com/dvds";

              Sitelink siteLink3 = new Sitelink();
              siteLink3.displayText = "New albums";
              siteLink3.destinationUrl = "http://www.example.com/albums/new";

              siteLinkExtension.sitelinks = new Sitelink[] {siteLink1, siteLink2, siteLink3};

              CampaignAdExtension campaignAdExtension = new CampaignAdExtension();
              campaignAdExtension.adExtension = siteLinkExtension;
              campaignAdExtension.campaignId = campaignId;

              // Create the operation.
              CampaignAdExtensionOperation operation = new CampaignAdExtensionOperation();
              operation.@operator = Operator.ADD;
              operation.operand = campaignAdExtension;

              // Create the sitelinks.
              CampaignAdExtensionReturnValue retVal =
              campaignExtensionService.mutate(new CampaignAdExtensionOperation[] {operation});

              return (retVal.value[0].adExtension as SitelinksExtension).sitelinks;
        }