use of com.google.api.ads.admanager.axis.v202202.VideoCreative in project googleads-java-lib by googleads.
the class CreateVideoCreatives 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(640);
size.setHeight(360);
size.setIsAspectRatio(false);
// Create an image creative.
VideoCreative videoCreative = new VideoCreative();
videoCreative.setName("Video creative #" + new Random().nextInt(Integer.MAX_VALUE));
videoCreative.setAdvertiserId(advertiserId);
videoCreative.setDestinationUrl("https://google.com");
videoCreative.setSize(size);
videoCreative.setVideoSourceUrl("https://storage.googleapis.com/interactive-media-ads/media/android.mp4");
videoCreative.setDuration(115000);
// Create the creatives on the server.
Creative[] creatives = creativeService.createCreatives(new Creative[] { videoCreative });
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(), ((VideoCreative) createdCreative).getVastPreviewUrl());
}
}
Aggregations