Search in sources :

Example 11 with Statement

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

Example 12 with Statement

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

the class GetGeoTargets method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param type the geo target type.
 * @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 type) throws IOException {
    // Get the PublisherQueryLanguageService.
    PublisherQueryLanguageServiceInterface pqlService = adManagerServices.get(session, PublisherQueryLanguageServiceInterface.class);
    // Create statement to select all targetable cities.
    StatementBuilder statementBuilder = new StatementBuilder().select("Id, Name, CanonicalParentId, ParentIds, CountryCode").from("Geo_Target").where("Type = :type and Targetable = true").orderBy("CountryCode ASC, Name ASC").offset(0).limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("type", type);
    // Default for result sets.
    ResultSet combinedResultSet = null;
    ResultSet resultSet;
    int i = 0;
    do {
        // Get all cities.
        resultSet = pqlService.select(statementBuilder.toStatement());
        // Combine result sets with previous ones.
        combinedResultSet = combinedResultSet == null ? resultSet : Pql.combineResultSets(combinedResultSet, resultSet);
        System.out.printf("%d) %d geo targets 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(type + "-", ".csv").toString();
    // Write the result set to a CSV.
    CsvFiles.writeCsv(Pql.resultSetToStringArrayList(combinedResultSet), filePath);
    System.out.printf("Geo targets saved to: %s%n", filePath);
}
Also used : PublisherQueryLanguageServiceInterface(com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) ResultSet(com.google.api.ads.admanager.axis.v202111.ResultSet)

Example 13 with Statement

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

the class GetAllUsers 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 UserService.
    UserServiceInterface userService = adManagerServices.get(session, UserServiceInterface.class);
    // Create a statement to get all users.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get users by statement.
        UserPage page = userService.getUsersByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (User user : page.getResults()) {
                System.out.printf("%d) User with ID %d and name '%s' was found.%n", i++, user.getId(), user.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : UserServiceInterface(com.google.api.ads.admanager.axis.v202111.UserServiceInterface) User(com.google.api.ads.admanager.axis.v202111.User) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) UserPage(com.google.api.ads.admanager.axis.v202111.UserPage)

Example 14 with Statement

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

the class GetAllUserTeamAssociations 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 UserTeamAssociationService.
    UserTeamAssociationServiceInterface userTeamAssociationService = adManagerServices.get(session, UserTeamAssociationServiceInterface.class);
    // Create a statement to select all user team associations.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("teamId ASC, userId ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get user team associations by statement.
        UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (UserTeamAssociation userTeamAssociation : page.getResults()) {
                System.out.printf("%d) User team associations with team ID %d and user ID %d was found.%n", i++, userTeamAssociation.getTeamId(), userTeamAssociation.getUserId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : UserTeamAssociationServiceInterface(com.google.api.ads.admanager.axis.v202111.UserTeamAssociationServiceInterface) UserTeamAssociation(com.google.api.ads.admanager.axis.v202111.UserTeamAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) UserTeamAssociationPage(com.google.api.ads.admanager.axis.v202111.UserTeamAssociationPage)

Example 15 with Statement

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

the class UpdateUserTeamAssociations method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param userId the user ID of the user team association to update.
 * @param teamId the team ID of the user team association to update.
 * @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, long userId, long teamId) throws RemoteException {
    // Get the UserTeamAssociationService.
    UserTeamAssociationServiceInterface userTeamAssociationService = adManagerServices.get(session, UserTeamAssociationServiceInterface.class);
    // Create a statement to only select a single user team association by ID.
    StatementBuilder statementBuilder = new StatementBuilder().where("userId = :userId AND teamId = :teamId").orderBy("userId, teamId ASC").limit(1).withBindVariableValue("userId", userId).withBindVariableValue("teamId", teamId);
    // Get the user team association.
    UserTeamAssociationPage page = userTeamAssociationService.getUserTeamAssociationsByStatement(statementBuilder.toStatement());
    UserTeamAssociation userTeamAssociation = Iterables.getOnlyElement(Arrays.asList(page.getResults()));
    // Update the user's access type on the team.
    userTeamAssociation.setOverriddenTeamAccessType(TeamAccessType.READ_ONLY);
    // Update the user team associations on the server.
    UserTeamAssociation[] userTeamAssociations = userTeamAssociationService.updateUserTeamAssociations(new UserTeamAssociation[] { userTeamAssociation });
    for (UserTeamAssociation updatedUserTeamAssociation : userTeamAssociations) {
        System.out.printf("User team association with user ID %d and team ID %d was updated.%n", updatedUserTeamAssociation.getUserId(), updatedUserTeamAssociation.getTeamId());
    }
}
Also used : UserTeamAssociationServiceInterface(com.google.api.ads.admanager.axis.v202111.UserTeamAssociationServiceInterface) UserTeamAssociation(com.google.api.ads.admanager.axis.v202111.UserTeamAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder) UserTeamAssociationPage(com.google.api.ads.admanager.axis.v202111.UserTeamAssociationPage)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)18 Statement (com.google.api.ads.admanager.axis.v202105.Statement)16 Statement (com.google.api.ads.admanager.axis.v202108.Statement)16 Statement (com.google.api.ads.admanager.axis.v202111.Statement)16 Statement (com.google.api.ads.admanager.axis.v202202.Statement)16 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202111.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202111.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202111.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202111.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202111.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202111.ResultSet)7 ArrayList (java.util.ArrayList)6 ProposalServiceInterface (com.google.api.ads.admanager.axis.v202111.ProposalServiceInterface)5 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202105.String_ValueMapEntry)4 String_ValueMapEntry (com.google.api.ads.admanager.axis.v202108.String_ValueMapEntry)4 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface)4 LineItem (com.google.api.ads.admanager.axis.v202111.LineItem)4 LineItemPage (com.google.api.ads.admanager.axis.v202111.LineItemPage)4