use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class RemoveAd method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group for the ad.
* @param adId the ID of the ad to remove.
* @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 adGroupId, long adId) throws RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create base class ad to avoid setting type specific fields.
Ad ad = new Ad();
ad.setId(adId);
// Create ad group ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(ad);
// Create operations.
AdGroupAdOperation operation = new AdGroupAdOperation();
operation.setOperand(adGroupAd);
operation.setOperator(Operator.REMOVE);
AdGroupAdOperation[] operations = new AdGroupAdOperation[] { operation };
// Remove ad.
AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
// Display ads.
for (AdGroupAd adGroupAdResult : result.getValue()) {
System.out.printf("Ad with ID %d and type '%s' was removed.%n", adGroupAdResult.getAd().getId(), adGroupAdResult.getAd().getAdType());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class RemoveCampaign method main.
public static void main(String[] args) {
AdWordsSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
// Construct an AdWordsSession.
session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
return;
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
return;
} catch (OAuthException oe) {
System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
return;
}
AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
RemoveCampaignParams params = new RemoveCampaignParams();
if (!params.parseArguments(args)) {
// Either pass the required parameters for this example on the command line, or insert them
// into the code here. See the parameter class definition above for descriptions.
params.campaignId = Long.parseLong("INSERT_CAMPAIGN_ID_HERE");
}
try {
runExample(adWordsServices, session, params.campaignId);
} catch (ApiException apiException) {
// ApiException is the base class for most exceptions thrown by an API request. Instances
// of this exception have a message and a collection of ApiErrors that indicate the
// type and underlying cause of the exception. Every exception object in the adwords.axis
// packages will return a meaningful value from toString
//
// ApiException extends RemoteException, so this catch block must appear before the
// catch block for RemoteException.
System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
if (apiException.getErrors() != null) {
int i = 0;
for (ApiError apiError : apiException.getErrors()) {
System.err.printf(" Error %d: %s%n", i++, apiError);
}
}
} catch (RemoteException re) {
System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class UpdateAdGroup method main.
public static void main(String[] args) {
AdWordsSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
// Construct an AdWordsSession.
session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
return;
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
return;
} catch (OAuthException oe) {
System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
return;
}
AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
UpdateAdGroupParams params = new UpdateAdGroupParams();
if (!params.parseArguments(args)) {
// Either pass the required parameters for this example on the command line, or insert them
// into the code here. See the parameter class definition above for descriptions.
params.adGroupId = Long.parseLong("INSERT_AD_GROUP_ID_HERE");
// Set this to null if you do not want to update the CPC bid.
params.cpcBidMicroAmount = Long.parseLong("INSERT_CPC_BID_MICRO_AMOUNT_HERE");
}
try {
runExample(adWordsServices, session, params.adGroupId, params.cpcBidMicroAmount);
} catch (ApiException apiException) {
// ApiException is the base class for most exceptions thrown by an API request. Instances
// of this exception have a message and a collection of ApiErrors that indicate the
// type and underlying cause of the exception. Every exception object in the adwords.axis
// packages will return a meaningful value from toString
//
// ApiException extends RemoteException, so this catch block must appear before the
// catch block for RemoteException.
System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
if (apiException.getErrors() != null) {
int i = 0;
for (ApiError apiError : apiException.getErrors()) {
System.err.printf(" Error %d: %s%n", i++, apiError);
}
}
} catch (RemoteException re) {
System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException 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]);
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddCampaignGroupsAndPerformanceTargets method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignIds the IDs of the campaigns to add to the campaign group.
* @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, List<Long> campaignIds) throws RemoteException {
CampaignGroup campaignGroup = createCampaignGroup(adWordsServices, session);
addCampaignsToGroup(adWordsServices, session, campaignGroup, campaignIds);
createPerformanceTarget(adWordsServices, session, campaignGroup);
}
Aggregations