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();
}
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.");
}
}
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;
}
Aggregations