Search in sources :

Example 1 with AssetReturnValue

use of com.google.api.ads.adwords.axis.v201809.cm.AssetReturnValue 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)

Aggregations

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