use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.
the class GetProductCategoryTaxonomy 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();
try {
runExample(adWordsServices, session);
} 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.lib.client.AdWordsSession in project googleads-java-lib by googleads.
the class AdWordsSessionUtilTest method testCidWithoutDash.
@Test
public void testCidWithoutDash() throws ValidationException {
AdWordsSession session = getTestAdWordsSessionWithoutCid();
session.setClientCustomerId(CID_WITHOUT_DASH);
assertEquals("Valid cid without dash test failed.", CID_VALID, AdWordsSessionUtil.getClientCustomerId(session));
}
use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.
the class AdWordsSessionUtilTest method testNullCidSession.
@Test
public void testNullCidSession() throws ValidationException {
AdWordsSession session = getTestAdWordsSessionWithoutCid();
assertEquals("Null cid test failed.", AdWordsSessionUtil.VIRTUAL_CID, AdWordsSessionUtil.getClientCustomerId(session));
}
use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.
the class AdWordsSessionUtilTest method testCidWithDash.
@Test
public void testCidWithDash() throws ValidationException {
AdWordsSession session = getTestAdWordsSessionWithoutCid();
session.setClientCustomerId(CID_WITH_DASH);
assertEquals("Valid cid with dash test failed.", CID_VALID, AdWordsSessionUtil.getClientCustomerId(session));
}
use of com.google.api.ads.adwords.lib.client.AdWordsSession in project googleads-java-lib by googleads.
the class AdWordsJaxWsModule method configure.
@Override
public void configure() {
bind(new TypeLiteral<HeaderHandler<AdWordsSession, AdWordsServiceDescriptor>>() {
}).to(new TypeLiteral<AdWordsJaxWsHeaderHandler>() {
});
install(new JaxWsModule());
install(new AdWordsModule());
install(new AdWordsSoapModule());
configureConfigurations(this.getClass().getResource("conf/props/build.properties"));
}
Aggregations