use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddProductPartitionTree 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();
AddProductPartitionTreeParams params = new AddProductPartitionTreeParams();
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");
}
try {
runExample(adWordsServices, session, params.adGroupId);
} 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 GetKeywordBidSimulations method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group.
* @param criterionId the ID of the criterion.
* @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 criterionId) throws RemoteException {
// Get the DataService.
DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);
// Create a query to select all keyword bid simulations for the ad group.
ServiceQuery query = new ServiceQuery.Builder().fields(DataField.AdGroupId, DataField.CriterionId, DataField.StartDate, DataField.EndDate, DataField.Bid, DataField.BiddableConversions, DataField.BiddableConversionsValue, DataField.LocalClicks, DataField.LocalCost, DataField.LocalImpressions).where(DataField.AdGroupId).equalTo(adGroupId).where(DataField.CriterionId).equalTo(criterionId).limit(0, PAGE_SIZE).build();
// Display bid landscapes.
CriterionBidLandscapePage page = null;
do {
query.nextPage(page);
// Retrieve keyword bid simulations one page at a time, continuing to request pages until all
// of them have been retrieved.
page = dataService.queryCriterionBidLandscape(query.toString());
if (page.getEntries() != null) {
for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
System.out.printf("Criterion bid landscape with ad group ID %d, criterion ID %d, " + "start date %s, end date %s, with landscape points:%n", criterionBidLandscape.getAdGroupId(), criterionBidLandscape.getCriterionId(), criterionBidLandscape.getStartDate(), criterionBidLandscape.getEndDate());
for (BidLandscapeLandscapePoint bidLanscapePoint : criterionBidLandscape.getLandscapePoints()) {
System.out.printf("\t{bid: %d clicks: %d cost: %d impressions: %d, biddable conversions: %.2f, " + "biddable conversions value: %.2f}%n", bidLanscapePoint.getBid().getMicroAmount(), bidLanscapePoint.getClicks(), bidLanscapePoint.getCost().getMicroAmount(), bidLanscapePoint.getImpressions(), bidLanscapePoint.getBiddableConversions(), bidLanscapePoint.getBiddableConversionsValue());
}
System.out.println(" was found.");
}
}
} while (query.hasNext(page));
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class GetKeywordBidSimulations 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();
GetKeywordBidSimulationsParams params = new GetKeywordBidSimulationsParams();
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");
params.criterionId = Long.parseLong("INSERT_CRITERION_ID_HERE");
}
try {
runExample(adWordsServices, session, params.adGroupId, params.criterionId);
} 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 AddPrices method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignId the ID of the campaign where price feed items will be added.
* @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 campaignId) throws ApiException, RemoteException {
// Get the CustomerExtensionSettingService.
CustomerExtensionSettingServiceInterface customerExtensionSettingService = adWordsServices.get(session, CustomerExtensionSettingServiceInterface.class);
// Create the price extension feed item.
PriceFeedItem priceFeedItem = new PriceFeedItem();
priceFeedItem.setPriceExtensionType(PriceExtensionType.SERVICES);
// Price qualifier is optional.
priceFeedItem.setPriceQualifier(PriceExtensionPriceQualifier.FROM);
priceFeedItem.setTrackingUrlTemplate("http://tracker.example.com/?u={lpurl}");
priceFeedItem.setLanguage("en");
FeedItemCampaignTargeting campaignTargeting = new FeedItemCampaignTargeting();
campaignTargeting.setTargetingCampaignId(campaignId);
priceFeedItem.setCampaignTargeting(campaignTargeting);
priceFeedItem.setScheduling(new FeedItemScheduling(new FeedItemSchedule[] { new FeedItemSchedule(DayOfWeek.SUNDAY, 10, MinuteOfHour.ZERO, 18, MinuteOfHour.ZERO), new FeedItemSchedule(DayOfWeek.SATURDAY, 10, MinuteOfHour.ZERO, 22, MinuteOfHour.ZERO) }));
// To create a price extension, at least three table rows are needed.
List<PriceTableRow> priceTableRows = new ArrayList<>();
String currencyCode = "USD";
priceTableRows.add(createPriceTableRow("Scrubs", "Body Scrub, Salt Scrub", "http://www.example.com/scrubs", "http://m.example.com/scrubs", 60000000, currencyCode, PriceExtensionPriceUnit.PER_HOUR));
priceTableRows.add(createPriceTableRow("Hair Cuts", "Once a month", "http://www.example.com/haircuts", "http://m.example.com/haircuts", 75000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
priceTableRows.add(createPriceTableRow("Skin Care Package", "Four times a month", "http://www.example.com/skincarepackage", null, 250000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
priceFeedItem.setTableRows(priceTableRows.toArray(new PriceTableRow[priceTableRows.size()]));
// Create your campaign extension settings. This associates the sitelinks
// to your campaign.
CustomerExtensionSetting customerExtensionSetting = new CustomerExtensionSetting();
customerExtensionSetting.setExtensionType(FeedType.PRICE);
ExtensionSetting extensionSetting = new ExtensionSetting();
extensionSetting.setExtensions(new ExtensionFeedItem[] { priceFeedItem });
customerExtensionSetting.setExtensionSetting(extensionSetting);
CustomerExtensionSettingOperation operation = new CustomerExtensionSettingOperation();
operation.setOperand(customerExtensionSetting);
operation.setOperator(Operator.ADD);
// Add the extensions.
CustomerExtensionSettingReturnValue returnValue = customerExtensionSettingService.mutate(new CustomerExtensionSettingOperation[] { operation });
if (returnValue.getValue() != null && returnValue.getValue().length > 0) {
CustomerExtensionSetting newExtensionSetting = returnValue.getValue(0);
System.out.printf("Extension setting with type '%s' was added.%n", newExtensionSetting.getExtensionType().getValue());
} else {
System.out.println("No extension settings were created.");
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.ApiException in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds 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();
AddSiteLinksUsingFeedsParams params = new AddSiteLinksUsingFeedsParams();
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");
params.feedName = "INSERT_FEED_NAME_HERE";
// Optional: Ad group to restrict targeting to.
params.adGroupId = null;
}
try {
runExample(adWordsServices, session, params.campaignId, params.feedName, params.adGroupId);
} 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);
}
}
Aggregations