Search in sources :

Example 36 with Statement

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

the class DeactivateUsers method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param userId the ID of the user to deactivate.
 * @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) throws RemoteException {
    // Get the UserService.
    UserServiceInterface userService = adManagerServices.get(session, UserServiceInterface.class);
    // Create a statement to select a user.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", userId);
    // 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 will be deactivated.%n", i++, user.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of users to be deactivated: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202108.DeactivateUsers action = new com.google.api.ads.admanager.axis.v202108.DeactivateUsers();
        // Perform action.
        UpdateResult result = userService.performUserAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of users deactivated: %d%n", result.getNumChanges());
        } else {
            System.out.println("No users were deactivated.");
        }
    }
}
Also used : UserServiceInterface(com.google.api.ads.admanager.axis.v202108.UserServiceInterface) User(com.google.api.ads.admanager.axis.v202108.User) UserPage(com.google.api.ads.admanager.axis.v202108.UserPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202108.UpdateResult)

Example 37 with Statement

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

the class GetAllSuggestedAdUnits 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 SuggestedAdUnitService.
    SuggestedAdUnitServiceInterface suggestedAdUnitService = adManagerServices.get(session, SuggestedAdUnitServiceInterface.class);
    // Create a statement to select all suggested ad units.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get suggested ad units by statement.
        SuggestedAdUnitPage page = suggestedAdUnitService.getSuggestedAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (SuggestedAdUnit suggestedAdUnit : page.getResults()) {
                System.out.printf("%d) Suggested ad unit with ID '%s', path '%s', " + "and number of requests %d was found.%n", i++, suggestedAdUnit.getId(), Joiner.on('/').join(suggestedAdUnit.getPath()), suggestedAdUnit.getNumRequests());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) SuggestedAdUnitServiceInterface(com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitServiceInterface) SuggestedAdUnit(com.google.api.ads.admanager.axis.v202108.SuggestedAdUnit) SuggestedAdUnitPage(com.google.api.ads.admanager.axis.v202108.SuggestedAdUnitPage)

Example 38 with Statement

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

the class GetAllTargetingPresets 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 TargetingPresetService.
    TargetingPresetServiceInterface targetingPresetService = adManagerServices.get(session, TargetingPresetServiceInterface.class);
    // Create a statement to get all targeting presets.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get targeting presets by statement.
        TargetingPresetPage page = targetingPresetService.getTargetingPresetsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (TargetingPreset targetingPreset : page.getResults()) {
                System.out.printf("%d) Targeting preset with ID %d and name '%s' was found.%n", i++, targetingPreset.getId(), targetingPreset.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : TargetingPresetServiceInterface(com.google.api.ads.admanager.axis.v202108.TargetingPresetServiceInterface) TargetingPresetPage(com.google.api.ads.admanager.axis.v202108.TargetingPresetPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) TargetingPreset(com.google.api.ads.admanager.axis.v202108.TargetingPreset)

Example 39 with Statement

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

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

Example 40 with Statement

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

the class GetAllContent 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 ContentService.
    ContentServiceInterface contentService = adManagerServices.get(session, ContentServiceInterface.class);
    // Create a statement to get all content.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get content by statement.
        ContentPage page = contentService.getContentByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Content content : page.getResults()) {
                String contentBundleIds = content.getContentBundleIds() == null ? "[]" : Arrays.toString(content.getContentBundleIds());
                System.out.printf("%d) Content with ID %d and name '%s' belonging to bundle IDs %s was found.%n", i++, content.getId(), content.getName(), contentBundleIds);
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : ContentServiceInterface(com.google.api.ads.admanager.axis.v202108.ContentServiceInterface) Content(com.google.api.ads.admanager.axis.v202108.Content) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder) ContentPage(com.google.api.ads.admanager.axis.v202108.ContentPage)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)119 Test (org.junit.Test)61 UpdateResult (com.google.api.ads.admanager.axis.v202108.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)13 CustomTargetingServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomTargetingServiceInterface)8 InventoryServiceInterface (com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface)8 AdUnit (com.google.api.ads.admanager.axis.v202108.AdUnit)7 AdUnitPage (com.google.api.ads.admanager.axis.v202108.AdUnitPage)7 PublisherQueryLanguageServiceInterface (com.google.api.ads.admanager.axis.v202108.PublisherQueryLanguageServiceInterface)7 ResultSet (com.google.api.ads.admanager.axis.v202108.ResultSet)7 LineItem (com.google.api.ads.admanager.axis.v202108.LineItem)6 LineItemPage (com.google.api.ads.admanager.axis.v202108.LineItemPage)6 LineItemServiceInterface (com.google.api.ads.admanager.axis.v202108.LineItemServiceInterface)6 CustomFieldServiceInterface (com.google.api.ads.admanager.axis.v202108.CustomFieldServiceInterface)5 Creative (com.google.api.ads.admanager.axis.v202108.Creative)4 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)4 Label (com.google.api.ads.admanager.axis.v202108.Label)4