Search in sources :

Example 6 with MediaServiceInterface

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());
}
Also used : MediaSize(com.google.api.ads.adwords.axis.v201809.cm.MediaSize) MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Media(com.google.api.ads.adwords.axis.v201809.cm.Media) Dimensions(com.google.api.ads.adwords.axis.v201809.cm.Dimensions) MediaBundle(com.google.api.ads.adwords.axis.v201809.cm.MediaBundle)

Example 7 with MediaServiceInterface

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();
}
Also used : MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Media(com.google.api.ads.adwords.axis.v201809.cm.Media) Image(com.google.api.ads.adwords.axis.v201809.cm.Image)

Example 8 with MediaServiceInterface

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];
}
Also used : MediaServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface) Image(com.google.api.ads.adwords.axis.v201809.cm.Image)

Aggregations

Image (com.google.api.ads.adwords.axis.v201809.cm.Image)6 MediaServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.MediaServiceInterface)6 Media (com.google.api.ads.adwords.axis.v201809.cm.Media)5 Dimensions (com.google.api.ads.adwords.axis.v201809.cm.Dimensions)3 MediaSize (com.google.api.ads.adwords.axis.v201809.cm.MediaSize)3 DynamicSettings (com.google.api.ads.adwords.axis.v201809.cm.DynamicSettings)2 Parameter (com.beust.jcommander.Parameter)1 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)1 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)1 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)1 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)1 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)1 AdGroupAdStatus (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdStatus)1 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 MediaBundle (com.google.api.ads.adwords.axis.v201809.cm.MediaBundle)1 MediaMediaType (com.google.api.ads.adwords.axis.v201809.cm.MediaMediaType)1 MediaPage (com.google.api.ads.adwords.axis.v201809.cm.MediaPage)1 Operator (com.google.api.ads.adwords.axis.v201809.cm.Operator)1