/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">The campaign ID.</param> /// <param name="videoId">The Youtube video ID.</param> public void Run(AdWordsUser user, long campaignId, string videoId) { // Get the VideoAdService. VideoAdService videoAdService = (VideoAdService) user.GetService( AdWordsService.v201402.VideoAdService); VideoAd videoAd = new VideoAd(); videoAd.campaignId = campaignId; videoAd.name = "My first video ad"; videoAd.status = VideoAdStatus.PAUSED; videoAd.headline = "Best headline ever"; videoAd.destinationUrl = "http://www.example.com"; videoAd.displayUrl = "www.example.com"; videoAd.description1 = "My favorite line 1"; videoAd.description2 = "My favorite line 2"; videoAd.videoId = videoId; VideoAdDisplayFormat_VideoAdStatusMapEntry statusByFormat = new VideoAdDisplayFormat_VideoAdStatusMapEntry(); statusByFormat.key = VideoAdDisplayFormat.TRUE_VIEW_IN_STREAM; statusByFormat.value = VideoAdStatus.ENABLED; videoAd.statusByFormat = new VideoAdDisplayFormat_VideoAdStatusMapEntry[] { statusByFormat }; try { VideoAdOperation operation = new VideoAdOperation(); operation.operand = videoAd; operation.@operator = Operator.ADD; VideoAdReturnValue retval = videoAdService.mutate(new VideoAdOperation[] { operation }); if (retval != null && retval.value != null && retval.value.Length > 0) { VideoAd newVideoAd = retval.value[0]; Console.WriteLine("Ad with id = {0} was added to campaign id {1}.", newVideoAd.id, newVideoAd.campaignId); } else { Console.WriteLine("No video ads were added."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to add video ad.", ex); } }