use of com.google.api.ads.adwords.axis.v201809.cm.AdOperation in project googleads-java-lib by googleads.
the class UpdateExpandedTextAd method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adId the ID of the ad to update.
* @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, Long adId) throws RemoteException {
// Get the AdService.
AdServiceInterface adService = adWordsServices.get(session, AdServiceInterface.class);
// Creates an expanded text ad using the provided ad ID.
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
expandedTextAd.setId(adId);
// Updates some properties of the expanded text ad.
expandedTextAd.setHeadlinePart1("Cruise to Pluto #" + System.currentTimeMillis());
expandedTextAd.setHeadlinePart2("Tickets on sale now");
expandedTextAd.setDescription("Best space cruise ever.");
expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/" });
expandedTextAd.setFinalMobileUrls(new String[] { "http://www.example.com/mobile" });
// Creates ad group ad operation and adds it to the list.
AdOperation operation = new AdOperation();
operation.setOperator(Operator.SET);
operation.setOperand(expandedTextAd);
// Updates the ad on the server.
ExpandedTextAd updatedAd = (ExpandedTextAd) adService.mutate(new AdOperation[] { operation }).getValue(0);
// Prints out some information.
System.out.printf("Expanded text ad with ID %d was updated.%n", updatedAd.getId());
System.out.printf("Headline part 1 is '%s'.%nHeadline part 2 is '%s'.%nDescription is '%s'.%n", updatedAd.getHeadlinePart1(), updatedAd.getHeadlinePart2(), updatedAd.getDescription());
System.out.printf("Final URL is '%s'.%nFinal mobile URL is '%s'.%n", updatedAd.getFinalUrls()[0], updatedAd.getFinalMobileUrls()[0]);
}
Aggregations