use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.
the class AdWordsSessionTest method testBuilder_returnsCopies.
/**
* Makes sure the builder returns a copy so that making (un-validated) changes in the builder
* doesn't mutate previously built objects.
*/
@Test
public void testBuilder_returnsCopies() throws Exception {
AdWordsSession.Builder builder = new AdWordsSession.Builder().withUserAgent("FooBar").withOAuth2Credential(credential).withEndpoint("https://www.google.com").withDeveloperToken("developerToken");
assertNotSame(build(builder), build(builder));
}
use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.
the class AdWordsSessionTest method testBuilder_withReportingConfiguration.
@Test
public void testBuilder_withReportingConfiguration() throws Exception {
ReportingConfiguration reportingConfiguration = new ReportingConfiguration.Builder().skipReportHeader(true).skipReportSummary(true).build();
AdWordsSession adWordsSession = build(new AdWordsSession.Builder().withUserAgent("FooBar").withEndpoint("https://www.google.com").withOAuth2Credential(credential).withDeveloperToken("developerToken").withReportingConfiguration(reportingConfiguration));
ReportingConfiguration sessionReportingConfig = adWordsSession.getReportingConfiguration();
assertNotNull("reporting configuration should not be null when passed to the builder", sessionReportingConfig);
}
use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.
the class AdWordsSessionTest method testBuilder_defaultEndpoint.
/**
* Tests that the builder builds correctly with a default endpoint.
*/
@Test
public void testBuilder_defaultEndpoint() throws Exception {
AdWordsSession adWordsSession = build(new AdWordsSession.Builder().withUserAgent("FooBar").withOAuth2Credential(credential).withDeveloperToken("developerToken"));
assertEquals("FooBar", adWordsSession.getUserAgent());
assertSame(credential, adWordsSession.getOAuth2Credential());
assertEquals(AdWordsSession.DEFAULT_ENDPOINT, adWordsSession.getEndpoint());
assertEquals("developerToken", adWordsSession.getDeveloperToken());
}
use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method main.
public static void main(String[] args) {
final AdWordsServicesInterface services = AdWordsServices.getInstance();
AdWordsSession session;
try {
Credential oAuth2Credential;
oAuth2Credential = new OfflineCredentials.Builder().forApi(OfflineCredentials.Api.ADWORDS).fromFile().build().generateCredential();
session = new Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file%n", DEFAULT_CONFIGURATION_FILENAME);
return;
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file%n", DEFAULT_CONFIGURATION_FILENAME);
return;
} catch (OAuthException oe) {
System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file%n", DEFAULT_CONFIGURATION_FILENAME);
return;
}
final AddShoppingDynamicRemarketingCampaignParams params = new AddShoppingDynamicRemarketingCampaignParams();
if (!params.parseArguments(args)) {
params.merchantId = Long.parseLong("INSERT_MERCHANT_ID");
params.budgetId = Long.parseLong("INSERT_BUDGET_ID");
params.userListId = Long.parseLong("INSERT_USER_LIST_ID");
}
try {
runExample(services, session, params.merchantId, params.budgetId, params.userListId);
} 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.print("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);
} catch (IOException e) {
System.err.printf("Request failed unexpectedly due to IOException: %s%n", e);
}
}
use of com.google.api.ads.adwords.lib.client.AdWordsSession.Builder in project googleads-java-lib by googleads.
the class AdWordsSessionTest method testBuilder_oAuth2.
/**
* Tests that the builder builds correctly for OAuth2.
*/
@Test
public void testBuilder_oAuth2() throws Exception {
AdWordsSession adWordsSession = build(new AdWordsSession.Builder().withUserAgent("FooBar").withEndpoint("https://www.google.com").withOAuth2Credential(credential).withDeveloperToken("developerToken"));
assertEquals("FooBar", adWordsSession.getUserAgent());
assertSame(credential, adWordsSession.getOAuth2Credential());
assertEquals("https://www.google.com", adWordsSession.getEndpoint());
assertEquals("developerToken", adWordsSession.getDeveloperToken());
}
Aggregations