use of com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface in project googleads-java-lib by googleads.
the class UploadMediaBundle method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @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(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws IOException {
// Get the MediaService.
MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
// Create HTML5 media.
byte[] html5Zip = com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/9Y7qI2");
// Create a media bundle containing the zip file with all the HTML5 components.
MediaBundle mediaBundle = new MediaBundle();
mediaBundle.setData(html5Zip);
mediaBundle.setType(MediaMediaType.MEDIA_BUNDLE);
// Upload HTML5 zip.
mediaBundle = (MediaBundle) mediaService.upload(new Media[] { mediaBundle })[0];
// Display HTML5 zip.
Map<MediaSize, Dimensions> dimensions = Maps.toMap(mediaBundle.getDimensions());
System.out.printf("HTML5 media with ID %d, dimensions '%dx%d', and MIME type '%s' " + "was uploaded.%n", mediaBundle.getMediaId(), dimensions.get(MediaSize.FULL).getWidth(), dimensions.get(MediaSize.FULL).getHeight(), mediaBundle.getMimeType());
}
use of com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface in project googleads-java-lib by googleads.
the class AddGmailAd method uploadImage.
/**
* Uploads an image.
*/
private static long uploadImage(AdWordsServicesInterface adWordsServices, AdWordsSession session, String url) throws IOException {
MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
// Create image.
Image image = new Image();
image.setData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl(url));
image.setType(MediaMediaType.IMAGE);
Media[] media = new Media[] { image };
// Upload image.
Media[] result = mediaService.upload(media);
return result[0].getMediaId();
}
use of com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method uploadImage.
/**
* Uploads the image from the specified {@code url}.
*
* @return the {@code Image} that was uploaded.
* @throws IOException if the image cannot be loaded.
*/
private static Image uploadImage(AdWordsServicesInterface services, AdWordsSession session, String url) throws IOException {
Image image = new Image();
image.setType(MediaMediaType.IMAGE);
image.setData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl(url));
MediaServiceInterface mediaService = services.get(session, MediaServiceInterface.class);
return (Image) mediaService.upload(new Media[] { image })[0];
}
Aggregations