use of com.google.api.ads.admanager.axis.v202108.SavedQuery in project googleads-java-lib by googleads.
the class RunSavedQuery method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param savedQueryId the ID of the saved query to run. This ID is part of the URL in the Ad
* Manager UI.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
* @throws InterruptedException if the thread is interrupted while waiting for the report to
* complete.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long savedQueryId) throws IOException, InterruptedException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
// Create statement to retrieve the saved query.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", savedQueryId);
SavedQueryPage page = reportService.getSavedQueriesByStatement(statementBuilder.toStatement());
SavedQuery savedQuery = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
if (!savedQuery.getIsCompatibleWithApiVersion()) {
throw new IllegalStateException("The saved query is not compatible with this API version.");
}
// Optionally modify the query.
ReportQuery reportQuery = savedQuery.getReportQuery();
reportQuery.setAdUnitView(ReportQueryAdUnitView.HIERARCHICAL);
// Create report job using the saved query.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
// Create report downloader.
ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
// Wait for the report to be ready.
reportDownloader.waitForReportReady();
// Change to your file location.
File file = File.createTempFile("inventory-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.");
}
use of com.google.api.ads.admanager.axis.v202108.SavedQuery in project googleads-java-lib by googleads.
the class RunSavedQuery method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param savedQueryId the ID of the saved query to run. This ID is part of the URL in the Ad
* Manager UI.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
* @throws InterruptedException if the thread is interrupted while waiting for the report to
* complete.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long savedQueryId) throws IOException, InterruptedException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
// Create statement to retrieve the saved query.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", savedQueryId);
SavedQueryPage page = reportService.getSavedQueriesByStatement(statementBuilder.toStatement());
SavedQuery savedQuery = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
if (!savedQuery.getIsCompatibleWithApiVersion()) {
throw new IllegalStateException("The saved query is not compatible with this API version.");
}
// Optionally modify the query.
ReportQuery reportQuery = savedQuery.getReportQuery();
reportQuery.setAdUnitView(ReportQueryAdUnitView.HIERARCHICAL);
// Create report job using the saved query.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
// Create report downloader.
ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
// Wait for the report to be ready.
reportDownloader.waitForReportReady();
// Change to your file location.
File file = File.createTempFile("inventory-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.");
}
use of com.google.api.ads.admanager.axis.v202108.SavedQuery in project googleads-java-lib by googleads.
the class RunSavedQuery method runExample.
/**
* Runs the example.
*
* @param adManagerServices the services factory.
* @param session the session.
* @param savedQueryId the ID of the saved query to run. This ID is part of the URL in the Ad
* Manager UI.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
* @throws IOException if unable to write the response to a file.
* @throws InterruptedException if the thread is interrupted while waiting for the report to
* complete.
*/
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long savedQueryId) throws IOException, InterruptedException {
// Get the ReportService.
ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
// Create statement to retrieve the saved query.
StatementBuilder statementBuilder = new StatementBuilder().where("id = :id").orderBy("id ASC").limit(1).withBindVariableValue("id", savedQueryId);
SavedQueryPage page = reportService.getSavedQueriesByStatement(statementBuilder.toStatement());
SavedQuery savedQuery = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
if (!savedQuery.getIsCompatibleWithApiVersion()) {
throw new IllegalStateException("The saved query is not compatible with this API version.");
}
// Optionally modify the query.
ReportQuery reportQuery = savedQuery.getReportQuery();
reportQuery.setAdUnitView(ReportQueryAdUnitView.HIERARCHICAL);
// Create report job using the saved query.
ReportJob reportJob = new ReportJob();
reportJob.setReportQuery(reportQuery);
// Run report job.
reportJob = reportService.runReportJob(reportJob);
// Create report downloader.
ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
// Wait for the report to be ready.
reportDownloader.waitForReportReady();
// Change to your file location.
File file = File.createTempFile("inventory-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.");
}
Aggregations