/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Create CreativeRemoteService instance. CreativeRemoteService service = (CreativeRemoteService)user.GetService( DfaService.v1_19.CreativeRemoteService); long creativeId = long.Parse(_T("INSERT_CREATIVE_ID")); long placementId = long.Parse(_T("INSERT_PLACEMENT_ID")); // Create creative placement assignment structure. CreativePlacementAssignment creativePlacementAssignment = new CreativePlacementAssignment(); creativePlacementAssignment.creativeId = creativeId; creativePlacementAssignment.placementId = placementId; creativePlacementAssignment.placementIds = new long[] { placementId }; try { // Assign creatives to placements. CreativePlacementAssignmentResult[] results = service.assignCreativesToPlacements( new CreativePlacementAssignment[] { creativePlacementAssignment }); // Display new ads that resulted from the assignment. foreach (CreativePlacementAssignmentResult result in results) { Console.WriteLine("Ad with name \"{0}\" and id \"{1}\" was created.", result.adName, result.adId); } } catch (Exception e) { Console.WriteLine("Failed to create ad. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Create CreativeRemoteService instance. CreativeRemoteService service = (CreativeRemoteService)user.GetService( DfaService.v1_20.CreativeRemoteService); long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); // Set up creative search criteria structure. CreativeSearchCriteria creativeSearchCriteria = new CreativeSearchCriteria(); creativeSearchCriteria.pageSize = 10; creativeSearchCriteria.advertiserId = advertiserId; try { // Get creatives for the selected criteria. CreativeRecordSet creatives = service.getCreatives(creativeSearchCriteria); // Display creative name and its id. if (creatives != null && creatives.records != null) { foreach (CreativeBase result in creatives.records) { Console.WriteLine("Creative with name \"{0}\" and id \"{1}\" was found.", result.name, result.id); } } else { Console.WriteLine("No creatives found for your criteria"); } } catch (Exception e) { Console.WriteLine("Failed to retrieve creatives. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Create CreateRemoteService instance. CreativeRemoteService service = (CreativeRemoteService)user.GetService( DfaService.v1_19.CreativeRemoteService); long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); string assetName = _T("INSERT_MOBILE_ASSET_NAME_HERE"); string pathToFile = _T("INSERT_PATH_TO_MOBILE_ASSET_HERE"); // Set mobile asset structure. CreativeAsset mobileAsset = new CreativeAsset(); mobileAsset.forHTMLCreatives = true; mobileAsset.advertiserId = advertiserId; mobileAsset.content = MediaUtilities.GetAssetDataFromUrl(new Uri(pathToFile)); mobileAsset.name = assetName; try { // Create mobile asset. CreativeAssetSaveResult result = service.saveCreativeAsset(mobileAsset); // Display asset file name. Console.WriteLine("Asset was saved with file name of \"{0}\".", result.savedFilename); } catch (Exception ex) { Console.WriteLine("Failed to create mobile asset. Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Request the creative service from the service client factory. CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService( DfaService.v1_19.CreativeRemoteService); long creativeId = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE")); try { // Fetch the In-Stream video creative which contains the asset to modify. CreativeBase rawCreative = creativeService.getCreative(creativeId); if (!(rawCreative is InStreamVideoCreative)) { Console.WriteLine("Unable to update creative with ID \"{0}\": not an In-Stream video " + "creative.", creativeId); } else { InStreamVideoCreative inStreamVideoCreative = (InStreamVideoCreative)rawCreative; // Modify the media files, companion ads, and/or non-linear ads. if (inStreamVideoCreative.mediaFiles != null) { foreach (InStreamMediaFile mediaFile in inStreamVideoCreative.mediaFiles) { mediaFile.pickedToServe = !mediaFile.pickedToServe; } } if (inStreamVideoCreative.companionAds != null) { foreach (InStreamCompanionAd companionAd in inStreamVideoCreative.companionAds) { companionAd.altText = companionAd.altText + " Updated."; } } if (inStreamVideoCreative.nonLinearAds != null) { foreach (InStreamNonLinearAd nonLinearAd in inStreamVideoCreative.nonLinearAds) { nonLinearAd.scalable = !nonLinearAd.scalable; } } CreativeSaveResult creativeSaveResult = creativeService.saveCreative(inStreamVideoCreative, 0); Console.WriteLine("Updated the In-Stream assets of In-Stream video creative with ID " + "\"{0}\".", creativeSaveResult.id); } } catch (Exception ex) { Console.WriteLine("Failed to update in-stream assets of in-stream video creative. " + "Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Create CreativeRemoteService instance. CreativeRemoteService service = (CreativeRemoteService)user.GetService( DfaService.v1_19.CreativeRemoteService); long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); String creativeName = _T("INSERT_CREATIVE_NAME_HERE"); String swfAssetFileName = _T("INSERT_SWF_ASSET_FILE_NAME_HERE"); String imgAssetFileName = _T("INSERT_IMG_ASSET_FILE_NAME_HERE"); long sizeId = long.Parse(_T("INSERT_SIZE_ID_HERE")); long typeId = long.Parse(_T("INSERT_TYPE_ID_HERE")); // Create flash inpage structure. FlashInpageCreative flashInpage = new FlashInpageCreative(); flashInpage.typeId = typeId; flashInpage.id = 0; flashInpage.name = creativeName; flashInpage.advertiserId = advertiserId; flashInpage.active = true; flashInpage.codeLocked = true; flashInpage.sizeId = sizeId; // Set parent flash asset structure. HTMLCreativeFlashAsset parentFlashAsset = new HTMLCreativeFlashAsset(); parentFlashAsset.assetFilename = swfAssetFileName; flashInpage.parentFlashAsset = parentFlashAsset; flashInpage.wmode = "opaque"; // Set backup image asset. HTMLCreativeAsset backupImageAsset = new HTMLCreativeAsset(); backupImageAsset.assetFilename = imgAssetFileName; flashInpage.backupImageAsset = backupImageAsset; // Set target window for backup image. TargetWindow backupImageTargetWindow = new TargetWindow(); backupImageTargetWindow.option = "_blank"; flashInpage.backupImageTargetWindow = backupImageTargetWindow; try { // Create flash inpage creative. CreativeSaveResult result = service.saveCreative(flashInpage, 0); // Display new creative id. Console.WriteLine("Flash inpage creative with id \"{0}\" was created.", result.id); } catch (Exception e) { Console.WriteLine("Failed to create advertiser. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Request the creative service from the service client factory. CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService( DfaService.v1_20.CreativeRemoteService); long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); long campaignId = 0; float videoDuration = float.Parse(_T("INSERT_VIDEO_DURATION_HERE")); string adId = _T("INSERT_VAST_AD_ID_HERE"); string surveyUrl = _T("INSERT_VAST_SURVEY_URL_HERE"); string clickThroughUrl = _T("INSERT_VAST_CLICK_THROUGH_URL_HERE"); // Create the In-Stream video creative. InStreamVideoCreative inStreamVideoCreative = new InStreamVideoCreative(); inStreamVideoCreative.advertiserId = advertiserId; inStreamVideoCreative.name = "In-Stream Video Creative #" + GetTimeStamp(); inStreamVideoCreative.videoDuration = videoDuration; // In-Stream video creatives have to be created inactive. One can only be // set active after at least one media file has been added to it or the API // will return an error message. inStreamVideoCreative.active = false; // Set the video details based on the Video Ad Serving Template (VAST) // specification. inStreamVideoCreative.adId = adId; inStreamVideoCreative.description = "You are viewing an In-Stream Video Creative"; inStreamVideoCreative.surveyUrl = surveyUrl; inStreamVideoCreative.clickThroughUrl = clickThroughUrl; try { // Save the In-Stream video creative. CreativeSaveResult creativeSaveResult = creativeService.saveCreative(inStreamVideoCreative, campaignId); // Display the new creative ID. Console.WriteLine("In-Stream video creative with ID \"{0}\" was created.", creativeSaveResult.id); } catch (Exception ex) { Console.WriteLine("Failed to create in-stream video creative. Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Create CreativeRemoteService instance. CreativeRemoteService service = (CreativeRemoteService)user.GetService( DfaService.v1_19.CreativeRemoteService); try { // Get creative types. CreativeType[] creativeTypes = service.getCreativeTypes(); // Display creative types and ids. foreach (CreativeType result in creativeTypes) { Console.WriteLine("Creative type name \"{0}\" with id \"{1}\" was found.", result.name, result.id); } } catch (Exception e) { Console.WriteLine("Failed to retrieve creative types. Exception says \"{0}\"", e.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Request the creative service from the service client factory. CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService( DfaService.v1_20.CreativeRemoteService); string assetName = _T("INSERT_ASSET_NAME_HERE"); string pathToFile = _T("INSERT_PATH_TO_FILE_HERE"); long creativeId = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE")); string assetToReplace = _T("INSERT_ASSET_TO_REPLACE_HERE"); // Create the In-Stream creative asset. CreativeAsset inStreamVideoAsset = new CreativeAsset(); inStreamVideoAsset.name = assetName; inStreamVideoAsset.content = MediaUtilities.GetAssetDataFromUrl( new Uri(pathToFile).AbsoluteUri); // Create an upload request to make this asset a companion ad file for an // existing In-Stream video creative. InStreamAssetUploadRequest inStreamAssetUploadRequest = new InStreamAssetUploadRequest(); inStreamAssetUploadRequest.companion = true; inStreamAssetUploadRequest.inStreamAsset = inStreamVideoAsset; inStreamAssetUploadRequest.creativeId = creativeId; try { // Replace the existing asset with a newly uploaded asset. InStreamVideoCreative inStreamVideoCreative = creativeService.replaceInStreamAsset(assetToReplace, inStreamAssetUploadRequest); // Display a success message. Console.WriteLine("Replaced companion ad asset \"{0}\" in In-Stream video creative " + "with ID \"{1}\".%n", assetToReplace, inStreamVideoCreative.id); } catch (Exception ex) { Console.WriteLine("Failed to replace companion ad asset in in-stream video creative. " + "Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Request the creative service from the service client factory. CreativeRemoteService creativeService = (CreativeRemoteService)user.GetService( DfaService.v1_19.CreativeRemoteService); string assetName = _T("INSERT_ASSET_NAME_HERE"); string pathToFile = _T("INSERT_PATH_TO_FILE_HERE"); long creativeId = long.Parse(_T("INSERT_IN_STREAM_VIDEO_CREATIVE_ID_HERE")); // Create the In-Stream video creative asset. CreativeAsset inStreamVideoAsset = new CreativeAsset(); inStreamVideoAsset.name = assetName; inStreamVideoAsset.content = MediaUtilities.GetAssetDataFromUrl( new Uri(pathToFile).AbsolutePath); // Create an upload request to make this asset a media file for an existing // In-Stream creative. InStreamAssetUploadRequest inStreamAssetUploadRequest = new InStreamAssetUploadRequest(); inStreamAssetUploadRequest.mediaFile = true; inStreamAssetUploadRequest.inStreamAsset = inStreamVideoAsset; inStreamAssetUploadRequest.creativeId = creativeId; try { // Save the media file. InStreamVideoCreative inStreamVideoCreative = creativeService.uploadInStreamAsset(inStreamAssetUploadRequest); // Display a success message. Console.WriteLine("Added a media file to In-Stream video creative with ID \"{0}\".", inStreamVideoCreative.id); } catch (Exception ex) { Console.WriteLine("Failed to add a media file to in-stream video creative. " + "Exception says \"{0}\"", ex.Message); } }
/// <summary> /// Run the code example. /// </summary> /// <param name="user">The Dfa user object running the code example. /// </param> public override void Run(DfaUser user) { // Create CreativeRemoteService instance. CreativeRemoteService service = (CreativeRemoteService)user.GetService( DfaService.v1_19.CreativeRemoteService); long advertiserId = long.Parse(_T("INSERT_ADVERTISER_ID_HERE")); String creativeName = _T("INSERT_CREATIVE_NAME_HERE"); String mobileAssetFileName = _T("INSERT_MOBILE_ASSET_FILE_NAME_HERE"); long typeId = long.Parse(_T("INSERT_TYPE_ID_HERE")); // Set mobile display creative structure. MobileDisplayCreative mobileDisplayCreative = new MobileDisplayCreative(); mobileDisplayCreative.advertiserId = advertiserId; mobileDisplayCreative.name = creativeName; mobileDisplayCreative.typeId = typeId; mobileDisplayCreative.archived = false; // Set mobile creative asset. HTMLCreativeAsset htmlCreativeAsset = new MobileDisplayCreativeAsset(); htmlCreativeAsset.assetFilename = mobileAssetFileName; mobileDisplayCreative.creativeAssets = new HTMLCreativeAsset[] { htmlCreativeAsset }; try { // Create mobile display creative. CreativeSaveResult creativeSaveResult = service.saveCreative(mobileDisplayCreative, 0); // Display new creative id. Console.WriteLine("Mobile display creative with id \"{0}\" was created.", creativeSaveResult.id); } catch (Exception ex) { Console.WriteLine("Failed to create display creative. Exception says \"{0}\"", ex.Message); } }