Search in sources :

Example 1 with ImageAsset

use of com.google.api.ads.adwords.axis.v201809.cm.ImageAsset in project googleads-java-lib by googleads.

the class AddMultiAssetResponsiveDisplayAd method uploadImageAsset.

/**
 * Creates and uploads an {@link ImageAsset} for the specified URL.
 *
 * @return the ID of the {@link ImageAsset}.
 * @throws IOException if unable to read the image from the specified URL.
 */
private static long uploadImageAsset(AdWordsServicesInterface adWordsServices, AdWordsSession session, String url) throws IOException {
    AssetServiceInterface assetService = adWordsServices.get(session, AssetServiceInterface.class);
    // Create the image asset.
    ImageAsset image = new ImageAsset();
    // Optional: Provide a unique friendly name to identify your asset. If you specify the assetName
    // field, then both the asset name and the image being uploaded should be unique, and should not
    // match another ACTIVE asset in this customer account.
    // image.setAssetName("Image asset #" + System.currentTimeMillis());
    image.setImageData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl(url));
    // Create the operation.
    AssetOperation operation = new AssetOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(image);
    // Create the asset and return the ID.
    return assetService.mutate(new AssetOperation[] { operation }).getValue(0).getAssetId();
}
Also used : AssetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset) AssetOperation(com.google.api.ads.adwords.axis.v201809.cm.AssetOperation)

Example 2 with ImageAsset

use of com.google.api.ads.adwords.axis.v201809.cm.ImageAsset in project googleads-java-lib by googleads.

the class UploadImageAsset 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 AssetService.
    AssetServiceInterface assetService = adWordsServices.get(session, AssetServiceInterface.class);
    // Create the image asset.
    ImageAsset image = new ImageAsset();
    // Optional: Provide a unique friendly name to identify your asset. If you specify the assetName
    // field, then both the asset name and the image being uploaded should be unique, and should not
    // match another ACTIVE asset in this customer account.
    // image.setAssetName("Jupiter Trip #" + System.currentTimeMillis());
    image.setImageData(com.google.api.ads.common.lib.utils.Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    // Create the operation.
    AssetOperation operation = new AssetOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(image);
    // Create the asset.
    AssetReturnValue result = assetService.mutate(new AssetOperation[] { operation });
    // Display the results.
    if (result != null && result.getValue() != null && result.getValue().length > 0) {
        Asset newAsset = result.getValue(0);
        System.out.printf("Image asset with ID %d and name '%s' was created.%n", newAsset.getAssetId(), newAsset.getAssetName());
    } else {
        System.out.println("No image asset was created.");
    }
}
Also used : AssetReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AssetReturnValue) Asset(com.google.api.ads.adwords.axis.v201809.cm.Asset) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset) AssetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset) AssetOperation(com.google.api.ads.adwords.axis.v201809.cm.AssetOperation)

Example 3 with ImageAsset

use of com.google.api.ads.adwords.axis.v201809.cm.ImageAsset in project googleads-java-lib by googleads.

the class AddMultiAssetResponsiveDisplayAd method createAssetLinkForImageAsset.

/**
 * Creates an {@link AssetLink} containing a {@link ImageAsset} with the specified asset ID.
 *
 * @param assetId ID of the image asset.
 * @return a new {@link AssetLink}
 */
private static AssetLink createAssetLinkForImageAsset(long assetId) {
    AssetLink assetLink = new AssetLink();
    ImageAsset imageAsset = new ImageAsset();
    imageAsset.setAssetId(assetId);
    assetLink.setAsset(imageAsset);
    return assetLink;
}
Also used : AssetLink(com.google.api.ads.adwords.axis.v201809.cm.AssetLink) ImageAsset(com.google.api.ads.adwords.axis.v201809.cm.ImageAsset)

Aggregations

ImageAsset (com.google.api.ads.adwords.axis.v201809.cm.ImageAsset)3 AssetOperation (com.google.api.ads.adwords.axis.v201809.cm.AssetOperation)2 AssetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface)2 Asset (com.google.api.ads.adwords.axis.v201809.cm.Asset)1 AssetLink (com.google.api.ads.adwords.axis.v201809.cm.AssetLink)1 AssetReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AssetReturnValue)1