Search in sources :

Example 1 with ImageRedirectCreative

use of com.google.api.ads.admanager.axis.v202202.ImageRedirectCreative in project googleads-java-lib by googleads.

the class CreateCreatives method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param advertiserId the ID of the advertiser (company) that all creatives will be assigned to.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long advertiserId) throws IOException {
    // Get the CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create creative size.
    Size size = new Size();
    size.setWidth(600);
    size.setHeight(315);
    size.setIsAspectRatio(false);
    // Create an image creative.
    ImageCreative imageCreative = new ImageCreative();
    imageCreative.setName("Image creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageCreative.setAdvertiserId(advertiserId);
    imageCreative.setDestinationUrl("http://google.com");
    imageCreative.setSize(size);
    // Create image asset.
    CreativeAsset creativeAsset = new CreativeAsset();
    creativeAsset.setFileName("image.jpg");
    creativeAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    creativeAsset.setSize(size);
    imageCreative.setPrimaryImageAsset(creativeAsset);
    // Create an image redirect creative.
    ImageRedirectCreative imageRedirectCreative = new ImageRedirectCreative();
    imageRedirectCreative.setName("Image redirect creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageRedirectCreative.setAdvertiserId(advertiserId);
    imageRedirectCreative.setDestinationUrl("http://google.com");
    imageRedirectCreative.setImageUrl("https://goo.gl/3b9Wfh");
    imageRedirectCreative.setSize(size);
    // Create the creatives on the server.
    Creative[] creatives = creativeService.createCreatives(new Creative[] { imageCreative, imageRedirectCreative });
    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.getClass().getSimpleName(), createdCreative.getPreviewUrl());
    }
}
Also used : Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202111.CreativeAsset) Creative(com.google.api.ads.admanager.axis.v202111.Creative) ImageCreative(com.google.api.ads.admanager.axis.v202111.ImageCreative) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202111.ImageRedirectCreative) Size(com.google.api.ads.admanager.axis.v202111.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202111.ImageRedirectCreative) ImageCreative(com.google.api.ads.admanager.axis.v202111.ImageCreative)

Example 2 with ImageRedirectCreative

use of com.google.api.ads.admanager.axis.v202202.ImageRedirectCreative in project googleads-java-lib by googleads.

the class CreateCreatives method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param advertiserId the ID of the advertiser (company) that all creatives will be assigned to.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long advertiserId) throws IOException {
    // Get the CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create creative size.
    Size size = new Size();
    size.setWidth(600);
    size.setHeight(315);
    size.setIsAspectRatio(false);
    // Create an image creative.
    ImageCreative imageCreative = new ImageCreative();
    imageCreative.setName("Image creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageCreative.setAdvertiserId(advertiserId);
    imageCreative.setDestinationUrl("http://google.com");
    imageCreative.setSize(size);
    // Create image asset.
    CreativeAsset creativeAsset = new CreativeAsset();
    creativeAsset.setFileName("image.jpg");
    creativeAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    creativeAsset.setSize(size);
    imageCreative.setPrimaryImageAsset(creativeAsset);
    // Create an image redirect creative.
    ImageRedirectCreative imageRedirectCreative = new ImageRedirectCreative();
    imageRedirectCreative.setName("Image redirect creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageRedirectCreative.setAdvertiserId(advertiserId);
    imageRedirectCreative.setDestinationUrl("http://google.com");
    imageRedirectCreative.setImageUrl("https://goo.gl/3b9Wfh");
    imageRedirectCreative.setSize(size);
    // Create the creatives on the server.
    Creative[] creatives = creativeService.createCreatives(new Creative[] { imageCreative, imageRedirectCreative });
    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.getClass().getSimpleName(), createdCreative.getPreviewUrl());
    }
}
Also used : Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202202.CreativeAsset) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202202.ImageRedirectCreative) ImageCreative(com.google.api.ads.admanager.axis.v202202.ImageCreative) Creative(com.google.api.ads.admanager.axis.v202202.Creative) Size(com.google.api.ads.admanager.axis.v202202.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202202.CreativeServiceInterface) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202202.ImageRedirectCreative) ImageCreative(com.google.api.ads.admanager.axis.v202202.ImageCreative)

Example 3 with ImageRedirectCreative

use of com.google.api.ads.admanager.axis.v202202.ImageRedirectCreative in project googleads-java-lib by googleads.

the class CreateCreatives method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param advertiserId the ID of the advertiser (company) that all creatives will be assigned to.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long advertiserId) throws IOException {
    // Get the CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create creative size.
    Size size = new Size();
    size.setWidth(600);
    size.setHeight(315);
    size.setIsAspectRatio(false);
    // Create an image creative.
    ImageCreative imageCreative = new ImageCreative();
    imageCreative.setName("Image creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageCreative.setAdvertiserId(advertiserId);
    imageCreative.setDestinationUrl("http://google.com");
    imageCreative.setSize(size);
    // Create image asset.
    CreativeAsset creativeAsset = new CreativeAsset();
    creativeAsset.setFileName("image.jpg");
    creativeAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    creativeAsset.setSize(size);
    imageCreative.setPrimaryImageAsset(creativeAsset);
    // Create an image redirect creative.
    ImageRedirectCreative imageRedirectCreative = new ImageRedirectCreative();
    imageRedirectCreative.setName("Image redirect creative #" + new Random().nextInt(Integer.MAX_VALUE));
    imageRedirectCreative.setAdvertiserId(advertiserId);
    imageRedirectCreative.setDestinationUrl("http://google.com");
    imageRedirectCreative.setImageUrl("https://goo.gl/3b9Wfh");
    imageRedirectCreative.setSize(size);
    // Create the creatives on the server.
    Creative[] creatives = creativeService.createCreatives(new Creative[] { imageCreative, imageRedirectCreative });
    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.getClass().getSimpleName(), createdCreative.getPreviewUrl());
    }
}
Also used : Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202108.CreativeAsset) Creative(com.google.api.ads.admanager.axis.v202108.Creative) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202108.ImageRedirectCreative) ImageCreative(com.google.api.ads.admanager.axis.v202108.ImageCreative) Size(com.google.api.ads.admanager.axis.v202108.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface) ImageRedirectCreative(com.google.api.ads.admanager.axis.v202108.ImageRedirectCreative) ImageCreative(com.google.api.ads.admanager.axis.v202108.ImageCreative)

Aggregations

Random (java.util.Random)3 Creative (com.google.api.ads.admanager.axis.v202108.Creative)1 CreativeAsset (com.google.api.ads.admanager.axis.v202108.CreativeAsset)1 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)1 ImageCreative (com.google.api.ads.admanager.axis.v202108.ImageCreative)1 ImageRedirectCreative (com.google.api.ads.admanager.axis.v202108.ImageRedirectCreative)1 Size (com.google.api.ads.admanager.axis.v202108.Size)1 Creative (com.google.api.ads.admanager.axis.v202111.Creative)1 CreativeAsset (com.google.api.ads.admanager.axis.v202111.CreativeAsset)1 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202111.CreativeServiceInterface)1 ImageCreative (com.google.api.ads.admanager.axis.v202111.ImageCreative)1 ImageRedirectCreative (com.google.api.ads.admanager.axis.v202111.ImageRedirectCreative)1 Size (com.google.api.ads.admanager.axis.v202111.Size)1 Creative (com.google.api.ads.admanager.axis.v202202.Creative)1 CreativeAsset (com.google.api.ads.admanager.axis.v202202.CreativeAsset)1 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202202.CreativeServiceInterface)1 ImageCreative (com.google.api.ads.admanager.axis.v202202.ImageCreative)1 ImageRedirectCreative (com.google.api.ads.admanager.axis.v202202.ImageRedirectCreative)1 Size (com.google.api.ads.admanager.axis.v202202.Size)1