Search in sources :

Example 1 with StatementBuilder

use of com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder 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.v202108.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202108.ResultSet)

Example 2 with StatementBuilder

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

the class GetLineItemsNamedLike 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 line items.
    StatementBuilder statementBuilder = new StatementBuilder().select("Id, Name, Status").from("Line_Item").where("Name LIKE 'line item%'").orderBy("Id ASC").offset(0).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for result sets.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        // Get line items like 'line item%'.
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        System.out.printf("%d) %d line items 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("Line-Items-Named-Like-", ".csv").toString();
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Line items saved to: %s%n", filePath);
}
Also used : PublisherQueryLanguageServiceInterface(com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202108.ResultSet)

Example 3 with StatementBuilder

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

the class GetRecentChanges method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param filePath file path where changes will be saved.
 * @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, String filePath) throws IOException {
    PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
    // Create statement to select recent changes. Change_History only supports ordering by
    // descending ChangeDateTime. Offset is not supported. To page, use the change ID of
    // the earliest change as a pagination token. A date time range is required
    // when querying this table.
    DateTime endDateTime = DateTime.now();
    DateTime startDateTime = endDateTime.minusDays(1);
    StatementBuilder statementBuilder = new StatementBuilder().select("Id, ChangeDateTime, EntityId, EntityType, Operation, UserId").from("Change_History").where("ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").orderBy("ChangeDateTime DESC").withBindVariableValue("startDateTime", DateTimes.toDateTime(startDateTime)).withBindVariableValue("endDateTime", DateTimes.toDateTime(endDateTime)).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Retrieve a small amount of changes at a time, paging through
    // until all changes have been retrieved.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        if (resultSet.getRows() != null && resultSet.getRows().length > 0) {
            // Get the earliest change ID in the result set.
            int numRows = resultSet.getRows().length;
            Row lastRow = resultSet.getRows(numRows - 1);
            String id = (String) Pql.getNativeValue(lastRow.getValues(0));
            System.out.printf("%d) %d changes prior to ID %s were found.%n", i++, numRows, id);
            // Use the earliest change ID in the result set to page.
            statementBuilder.where("Id < :id AND ChangeDateTime < :endDateTime AND ChangeDateTime > :startDateTime").withBindVariableValue("id", id);
        }
    } while (resultSet.getRows() != null && resultSet.getRows().length > 0);
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Recent changes saved to: %s%n", filePath);
}
Also used : PublisherQueryLanguageServiceInterface(com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202108.ResultSet) Row(com.google.api.ads.admanager.axis.v202108.Row) DateTime(org.joda.time.DateTime)

Example 4 with StatementBuilder

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

the class GetAllSites 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 SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Create a statement to get all sites.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get sites by statement.
        SitePage page = siteService.getSitesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Site site : page.getResults()) {
                System.out.printf("%d) Site with ID %d and URL '%s' was found.%n", i++, site.getId(), site.getUrl());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : Site(com.google.api.ads.admanager.axis.v202108.Site) SitePage(com.google.api.ads.admanager.axis.v202108.SitePage) SiteServiceInterface(com.google.api.ads.admanager.axis.v202108.SiteServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)

Example 5 with StatementBuilder

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

the class GetAllLineItems 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 line items.
    StatementBuilder statementBuilder = new StatementBuilder().select("Id, Name, Status").from("Line_Item").orderBy("Id ASC").offset(0).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for result sets.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        // Get all line items.
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        System.out.printf("%d) %d line items 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("Line-Items-", ".csv").toString();
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Line items saved to: %s%n", filePath);
}
Also used : PublisherQueryLanguageServiceInterface(com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202108.ResultSet)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)120 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)120 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)120 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)120 ArrayList (java.util.ArrayList)24 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)18 UpdateResult (com.google.api.ads.admanager.axis.v202205.UpdateResult)18 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface)8 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)8 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)8 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202202.CustomTargetingServiceInterface)6 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)5 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202111.InventoryServiceInterface)5 ProposalServiceInterface (com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface)5 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)5 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)5 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202202.PublisherQueryLanguageServiceInterface)5