use of com.recurly.v3.ApiException in project googleads-java-lib by googleads.
the class UpdateProposalLineItems method main.
public static void main(String[] args) {
AdManagerSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.AD_MANAGER).fromFile().build().generateCredential();
// Construct a AdManagerSession.
session = new AdManagerSession.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;
}
AdManagerServices adManagerServices = new AdManagerServices();
UpdateProposalLineItemsParams params = new UpdateProposalLineItemsParams();
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.proposalLineItemId = Long.parseLong("INSERT_PROPOSAL_LINE_ITEM_ID_HERE");
}
try {
runExample(adManagerServices, session, params.proposalLineItemId);
} 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 admanager.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.recurly.v3.ApiException in project googleads-java-lib by googleads.
the class GetAllProposals method main.
public static void main(String[] args) {
AdManagerSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.AD_MANAGER).fromFile().build().generateCredential();
// Construct a AdManagerSession.
session = new AdManagerSession.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;
}
AdManagerServices adManagerServices = new AdManagerServices();
try {
runExample(adManagerServices, 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 admanager.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.recurly.v3.ApiException in project googleads-java-lib by googleads.
the class GetGeoTargets method main.
public static void main(String[] args) {
AdManagerSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.AD_MANAGER).fromFile().build().generateCredential();
// Construct a AdManagerSession.
session = new AdManagerSession.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;
}
AdManagerServices adManagerServices = new AdManagerServices();
try {
runExample(adManagerServices, session, GEO_TARGET_TYPE);
} 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 admanager.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);
} catch (IOException ioe) {
System.err.printf("Example failed due to IOException: %s%n", ioe);
}
}
use of com.recurly.v3.ApiException in project googleads-java-lib by googleads.
the class GetMcmEarnings method main.
public static void main(String[] args) {
AdManagerSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.AD_MANAGER).fromFile().build().generateCredential();
// Construct a AdManagerSession.
session = new AdManagerSession.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;
}
AdManagerServices adManagerServices = new AdManagerServices();
try {
runExample(adManagerServices, 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 admanager.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);
} catch (IOException ioe) {
System.err.printf("Example failed due to IOException: %s%n", ioe);
}
}
use of com.recurly.v3.ApiException in project googleads-java-lib by googleads.
the class AsyncDownloadReport method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @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(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
// Create report query.
ReportQuery reportQuery = new ReportQuery();
reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.ORDER_ID });
reportQuery.setColumns(new Column[] { Column.AD_SERVER_IMPRESSIONS });
// Set the dynamic date range type or a custom start and end date.
reportQuery.setDateRangeType(DateRangeType.LAST_WEEK);
// Create report job.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
// Create report downloader.
final ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
reportDownloader.whenReportReady(new ReportCallback() {
@Override
public void onSuccess() {
try {
// Change to your file location.
File file = File.createTempFile("async-report-", ".csv.gz");
System.out.printf("Downloading report to %s ...", file.toString());
// Download the report.
ReportDownloadOptions options = new ReportDownloadOptions();
options.setExportFormat(ExportFormat.CSV_DUMP);
options.setUseGzipCompression(true);
URL url = reportDownloader.getDownloadUrl(options);
Resources.asByteSource(url).copyTo(Files.asByteSink(file));
System.out.println("done.");
} catch (IOException e) {
System.err.println("Failed to write report.");
}
}
@Override
public void onInterruption() {
System.err.println("Report download interupted.");
}
@Override
public void onFailure() {
System.err.println("Report download failed.");
}
@Override
public void onException(Exception e) {
System.err.println("Report download failed.");
e.printStackTrace();
}
});
}
Aggregations