Search in sources :

Example 11 with UserTeamAssociationPage

use of com.google.api.ads.admanager.axis.v202111.UserTeamAssociationPage 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.v202108.UserTeamAssociationServiceInterface) UserTeamAssociation(com.google.api.ads.admanager.axis.v202108.UserTeamAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) UserTeamAssociationPage(com.google.api.ads.admanager.axis.v202108.UserTeamAssociationPage)

Example 12 with UserTeamAssociationPage

use of com.google.api.ads.admanager.axis.v202111.UserTeamAssociationPage 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.v202108.UserTeamAssociationServiceInterface) UserTeamAssociation(com.google.api.ads.admanager.axis.v202108.UserTeamAssociation) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) UserTeamAssociationPage(com.google.api.ads.admanager.axis.v202108.UserTeamAssociationPage)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 UserTeamAssociation (com.google.api.ads.admanager.axis.v202108.UserTeamAssociation)4 UserTeamAssociationPage (com.google.api.ads.admanager.axis.v202108.UserTeamAssociationPage)4 UserTeamAssociationServiceInterface (com.google.api.ads.admanager.axis.v202108.UserTeamAssociationServiceInterface)4 UserTeamAssociation (com.google.api.ads.admanager.axis.v202111.UserTeamAssociation)4 UserTeamAssociationPage (com.google.api.ads.admanager.axis.v202111.UserTeamAssociationPage)4 UserTeamAssociationServiceInterface (com.google.api.ads.admanager.axis.v202111.UserTeamAssociationServiceInterface)4 UserTeamAssociation (com.google.api.ads.admanager.axis.v202202.UserTeamAssociation)4 UserTeamAssociationPage (com.google.api.ads.admanager.axis.v202202.UserTeamAssociationPage)4 UserTeamAssociationServiceInterface (com.google.api.ads.admanager.axis.v202202.UserTeamAssociationServiceInterface)4 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)1 UpdateResult (com.google.api.ads.admanager.axis.v202111.UpdateResult)1 UpdateResult (com.google.api.ads.admanager.axis.v202202.UpdateResult)1