public static void runExample(DfpServices dfpServices, DfpSession session, long advertiserId) throws Exception { // Get the CreativeService. CreativeServiceInterface creativeService = dfpServices.get(session, CreativeServiceInterface.class); // Create creative size. Size size = new Size(); size.setWidth(300); size.setHeight(250); size.setIsAspectRatio(false); // Create a custom creative. CustomCreative customCreative = new CustomCreative(); customCreative.setName("Custom creative #" + new Random().nextInt(Integer.MAX_VALUE)); customCreative.setAdvertiserId(advertiserId); customCreative.setDestinationUrl("http://google.com"); customCreative.setSize(size); // Set the custom creative image asset. CustomCreativeAsset customCreativeAsset = new CustomCreativeAsset(); customCreativeAsset.setMacroName("IMAGE_ASSET"); customCreativeAsset.setAssetByteArray( Media.getMediaDataFromUrl( "http://www.google.com/intl/en/adwords/select/images/samples/inline.jpg")); // Filenames must be unique. customCreativeAsset.setFileName( String.format("image%s.jpg", new Random().nextInt(Integer.MAX_VALUE))); customCreative.setCustomCreativeAssets(new CustomCreativeAsset[] {customCreativeAsset}); // Set the HTML snippet using the custom creative asset macro. customCreative.setHtmlSnippet( "<a href='%%CLICK_URL_UNESC%%%%DEST_URL%%'>" + "<img src='%%FILE:" + customCreativeAsset.getMacroName() + "%%'/>" + "</a><br>Click above for great deals!"); // Create the creative on the server. Creative[] creatives = creativeService.createCreatives(new Creative[] {customCreative}); for (Creative createdCreative : creatives) { System.out.printf( "A creative with ID \"%d\", name \"%s\", and type \"%s\"" + " was created and can be previewed at: %s\n", createdCreative.getId(), createdCreative.getName(), createdCreative.getCreativeType(), createdCreative.getPreviewUrl()); } }
public static void runExample( DfaServices dfaServices, DfaSession session, String assetName, String pathToFile, long advertiserId) throws Exception { // Request the service. CreativeRemote service = dfaServices.get(session, CreativeRemote.class); // Create the HTML asset. CreativeAsset swfAsset = new CreativeAsset(); swfAsset.setForHTMLCreatives(true); swfAsset.setName(assetName); swfAsset.setContent(Media.getMediaDataFromFile(pathToFile)); swfAsset.setAdvertiserId(advertiserId); // Save the asset. CreativeAssetSaveResult creativeAssetSaveResult = service.saveCreativeAsset(swfAsset); // Display the new asset file name. System.out.printf( "Asset was saved with file name of \"%s\".%n", creativeAssetSaveResult.getSavedFilename()); }