Search in sources :

Example 1 with AssetServiceInterface

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

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

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

the class GetAllImageAssets 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.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the AdGroupAdService.
    AssetServiceInterface assetService = adWordsServices.get(session, AssetServiceInterface.class);
    int offset = 0;
    boolean morePages = true;
    // Create the selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AssetField.AssetName, AssetField.AssetStatus, AssetField.ImageFileSize, AssetField.ImageWidth, AssetField.ImageHeight, AssetField.ImageFullSizeUrl).offset(offset).limit(PAGE_SIZE).equals(AssetField.AssetSubtype, AssetType.IMAGE.getValue()).build();
    int totalEntries = 0;
    while (morePages) {
        // Get the image assets.
        AssetPage page = assetService.get(selector);
        // Display the results.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            totalEntries = page.getTotalNumEntries();
            int i = selector.getPaging().getStartIndex();
            for (Asset asset : page.getEntries()) {
                System.out.printf("%d) Image asset with ID %d, name '%s', and status '%s' was found.%n", i, asset.getAssetId(), asset.getAssetName(), asset.getAssetStatus());
            }
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
        morePages = offset < page.getTotalNumEntries();
    }
    System.out.printf("Found %d image assets.%n", totalEntries);
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) Asset(com.google.api.ads.adwords.axis.v201809.cm.Asset) AssetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface) AssetPage(com.google.api.ads.adwords.axis.v201809.cm.AssetPage) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Aggregations

AssetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AssetServiceInterface)3 Asset (com.google.api.ads.adwords.axis.v201809.cm.Asset)2 AssetOperation (com.google.api.ads.adwords.axis.v201809.cm.AssetOperation)2 ImageAsset (com.google.api.ads.adwords.axis.v201809.cm.ImageAsset)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AssetPage (com.google.api.ads.adwords.axis.v201809.cm.AssetPage)1 AssetReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AssetReturnValue)1 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)1