Search in sources :

Example 26 with Location

use of com.google.api.ads.admanager.axis.v202205.Location in project googleads-java-lib by googleads.

the class RunReachReport 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.
 * @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) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.COUNTRY_NAME, Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME });
    reportQuery.setColumns(new Column[] { Column.UNIQUE_REACH_FREQUENCY, Column.UNIQUE_REACH_IMPRESSIONS, Column.UNIQUE_REACH });
    // Set the dynamic date range type or a custom start and end date that is
    // the beginning of the week (Sunday) to the end of the week (Saturday), or
    // the first of the month to the end of the month.
    reportQuery.setDateRangeType(DateRangeType.REACH_LIFETIME);
    // Create report job.
    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("reach-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.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202205.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202205.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202205.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202205.ReportServiceInterface) ReportJob(com.google.api.ads.admanager.axis.v202205.ReportJob) File(java.io.File) URL(java.net.URL)

Example 27 with Location

use of com.google.api.ads.admanager.axis.v202205.Location in project googleads-java-lib by googleads.

the class RunReachReportWithAdUnitDimensions 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.
 * @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) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.MONTH_AND_YEAR, Dimension.COUNTRY_NAME, Dimension.AD_UNIT_ID, Dimension.AD_UNIT_NAME });
    reportQuery.setColumns(new Column[] { Column.UNIQUE_REACH_FREQUENCY, Column.UNIQUE_REACH_IMPRESSIONS, Column.UNIQUE_REACH });
    // Set the dynamic date range type or a custom start and end date that is
    // the beginning of the week (Sunday) to the end of the week (Saturday), or
    // the first of the month to the end of the month.
    reportQuery.setDateRangeType(DateRangeType.LAST_MONTH);
    reportQuery.setAdUnitView(ReportQueryAdUnitView.FLAT);
    // Create report job.
    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("reach-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.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202205.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202205.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202205.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202205.ReportServiceInterface) ReportJob(com.google.api.ads.admanager.axis.v202205.ReportJob) File(java.io.File) URL(java.net.URL)

Example 28 with Location

use of com.google.api.ads.admanager.axis.v202205.Location in project googleads-java-lib by googleads.

the class RunReportWithCustomFields method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customFieldId the ID of the custom field to include in the report.
 * @param customDimensionKeyId the ID of the custom key to include as a dimension in the report.
 * @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 customFieldId, long customDimensionKeyId) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.DATE, Dimension.CUSTOM_DIMENSION, Dimension.LINE_ITEM_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_MONTH);
    // Set the custom field IDs.
    reportQuery.setCustomFieldIds(new long[] { customFieldId });
    // Set the custom dimension IDs.
    reportQuery.setCustomDimensionKeyIds(new long[] { customDimensionKeyId });
    // Create report job.
    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("custom-field-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.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202205.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202205.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202205.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202205.ReportServiceInterface) ReportJob(com.google.api.ads.admanager.axis.v202205.ReportJob) File(java.io.File) URL(java.net.URL)

Example 29 with Location

use of com.google.api.ads.admanager.axis.v202205.Location 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.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202205.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202205.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202205.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202205.ReportServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) SavedQueryPage(com.google.api.ads.admanager.axis.v202205.SavedQueryPage) ReportJob(com.google.api.ads.admanager.axis.v202205.ReportJob) File(java.io.File) URL(java.net.URL) SavedQuery(com.google.api.ads.admanager.axis.v202205.SavedQuery)

Example 30 with Location

use of com.google.api.ads.admanager.axis.v202205.Location in project googleads-java-lib by googleads.

the class GetAllProgrammaticBuyers 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.
 * @throws IOException if unable to write the response to a file.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException {
    // Get the PublisherQueryLanguageService.
    PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
    // Create statement to select all programmatic buyers.
    StatementBuilder statementBuilder = new StatementBuilder().select("BuyerAccountId, Name").from("Programmatic_Buyer").orderBy("BuyerAccountId ASC").offset(0).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for result sets.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        // Get all programmatic buyers.
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        System.out.printf("%d) %d programmatic buyers beginning at offset %d were found.%n", i++, resultSet.getRows() == null ? 0 : resultSet.getRows().length, statementBuilder.getOffset());
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (resultSet.getRows() != null && resultSet.getRows().length > 0);
    // Change to your file location.
    String filePath = File.createTempFile("Programmatic-Buyers-", ".csv").toString();
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Programmatic buyers saved to: %s%n", filePath);
}
Also used : PublisherQueryLanguageServiceInterface(com.google.api.ads.admanager.axis.v202205.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202205.ResultSet)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)8 Random (java.util.Random)8 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202205.ReportDownloader)7 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202205.ReportDownloadOptions)7 ReportJob (com.google.api.ads.admanager.axis.v202205.ReportJob)7 ReportQuery (com.google.api.ads.admanager.axis.v202205.ReportQuery)7 ReportServiceInterface (com.google.api.ads.admanager.axis.v202205.ReportServiceInterface)7 File (java.io.File)7 URL (java.net.URL)7 Location (org.openqa.selenium.html5.Location)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202205.PublisherQueryLanguageServiceInterface)6 ResultSet (com.google.api.ads.admanager.axis.v202205.ResultSet)6 Test (org.junit.Test)5 LocationContext (org.openqa.selenium.html5.LocationContext)5 WebElement (org.openqa.selenium.WebElement)3 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)3 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)2 GeoTargeting (com.google.api.ads.admanager.axis.v202108.GeoTargeting)2 InventoryTargeting (com.google.api.ads.admanager.axis.v202108.InventoryTargeting)2 Location (com.google.api.ads.admanager.axis.v202108.Location)2