Search in sources :

Example 6 with NetworkServiceInterface

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

the class GetTopLevelAdUnits 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 InventoryService.
    InventoryServiceInterface inventoryService = adManagerServices.get(session, InventoryServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Set the parent ad unit's ID for all children ad units to be fetched from.
    String parentAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
    // Create a statement to select ad units under the parent ad unit.
    StatementBuilder statementBuilder = new StatementBuilder().where("parentId = :parentId").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("parentId", parentAdUnitId);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get ad units by statement.
        AdUnitPage page = inventoryService.getAdUnitsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (AdUnit adUnit : page.getResults()) {
                System.out.printf("%d) Ad unit with ID '%s' and name '%s' was found.%n", i++, adUnit.getId(), adUnit.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface) AdUnitPage(com.google.api.ads.admanager.axis.v202108.AdUnitPage) AdUnit(com.google.api.ads.admanager.axis.v202108.AdUnit) InventoryServiceInterface(com.google.api.ads.admanager.axis.v202108.InventoryServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)

Example 7 with NetworkServiceInterface

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

the class GetAllNetworks 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 NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get all networks that you have access to with the current authentication
    // credentials.
    Network[] networks = networkService.getAllNetworks();
    int i = 0;
    for (Network network : networks) {
        System.out.printf("%d) Network with network code '%s' and display name '%s' was found.%n", i++, network.getNetworkCode(), network.getDisplayName());
    }
    System.out.printf("Number of networks found: %d%n", networks.length);
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface) Network(com.google.api.ads.admanager.axis.v202108.Network)

Example 8 with NetworkServiceInterface

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

the class CreateAudienceSegments method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param customTargetingKeyId the ID of the custom criteria to be used in the segment rule.
 * @param customTargetingValueId the custom targeting value ID.
 * @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 customTargetingKeyId, long customTargetingValueId) throws RemoteException {
    // Get the AudienceSegmentService.
    AudienceSegmentServiceInterface audienceSegmentService = adManagerServices.get(session, AudienceSegmentServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get the root ad unit ID used to target the whole site.
    String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
    // Create inventory targeting.
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    // Create ad unit targeting for the root ad unit (i.e. the whole network).
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId(rootAdUnitId);
    adUnitTargeting.setIncludeDescendants(true);
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { adUnitTargeting });
    // Create the custom criteria to be used in the segment rule.
    // TARGETING_KEY_ID == TARGETING_VALUE_ID
    CustomCriteria customCriteria = new CustomCriteria();
    customCriteria.setKeyId(customTargetingKeyId);
    customCriteria.setOperator(CustomCriteriaComparisonOperator.IS);
    customCriteria.setValueIds(new long[] { customTargetingValueId });
    // Create the custom criteria expression.
    CustomCriteriaSet topCustomCriteriaSet = new CustomCriteriaSet();
    topCustomCriteriaSet.setLogicalOperator(CustomCriteriaSetLogicalOperator.AND);
    topCustomCriteriaSet.setChildren(new CustomCriteriaNode[] { customCriteria });
    // Create the audience segment rule.
    FirstPartyAudienceSegmentRule rule = new FirstPartyAudienceSegmentRule();
    rule.setInventoryRule(inventoryTargeting);
    rule.setCustomCriteriaRule(topCustomCriteriaSet);
    // Create an audience segment.
    RuleBasedFirstPartyAudienceSegment audienceSegment = new RuleBasedFirstPartyAudienceSegment();
    audienceSegment.setName("Sports enthusiasts audience segment #" + new Random().nextInt(Integer.MAX_VALUE));
    audienceSegment.setDescription("Sports enthusiasts between the ages of 20 and 30.");
    audienceSegment.setPageViews(6);
    audienceSegment.setRecencyDays(6);
    audienceSegment.setMembershipExpirationDays(88);
    audienceSegment.setRule(rule);
    // Create the audience segment on the server.
    AudienceSegment[] audienceSegments = audienceSegmentService.createAudienceSegments(new FirstPartyAudienceSegment[] { audienceSegment });
    for (AudienceSegment createdAudienceSegment : audienceSegments) {
        System.out.printf("An audience segment with ID %d, name '%s', and type '%s' was created.%n", createdAudienceSegment.getId(), createdAudienceSegment.getName(), createdAudienceSegment.getType());
    }
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface) AdUnitTargeting(com.google.api.ads.admanager.axis.v202108.AdUnitTargeting) Random(java.util.Random) FirstPartyAudienceSegmentRule(com.google.api.ads.admanager.axis.v202108.FirstPartyAudienceSegmentRule) CustomCriteria(com.google.api.ads.admanager.axis.v202108.CustomCriteria) InventoryTargeting(com.google.api.ads.admanager.axis.v202108.InventoryTargeting) CustomCriteriaSet(com.google.api.ads.admanager.axis.v202108.CustomCriteriaSet) RuleBasedFirstPartyAudienceSegment(com.google.api.ads.admanager.axis.v202108.RuleBasedFirstPartyAudienceSegment) FirstPartyAudienceSegment(com.google.api.ads.admanager.axis.v202108.FirstPartyAudienceSegment) AudienceSegment(com.google.api.ads.admanager.axis.v202108.AudienceSegment) RuleBasedFirstPartyAudienceSegment(com.google.api.ads.admanager.axis.v202108.RuleBasedFirstPartyAudienceSegment) AudienceSegmentServiceInterface(com.google.api.ads.admanager.axis.v202108.AudienceSegmentServiceInterface)

Example 9 with NetworkServiceInterface

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

the class CreateTrafficForecastSegments 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 adjustment service and the network service.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get the root ad unit ID used to target the whole site.
    String rootAdUnitId = networkService.getCurrentNetwork().getEffectiveRootAdUnitId();
    // Create inventory targeting.
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    // Create ad unit targeting for the root ad unit (i.e. the whole network).
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId(rootAdUnitId);
    adUnitTargeting.setIncludeDescendants(true);
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { adUnitTargeting });
    // Create targeting for United States traffic.
    GeoTargeting geoTargeting = new GeoTargeting();
    Location countryLocation = new Location();
    countryLocation.setId(2840L);
    geoTargeting.setTargetedLocations(new Location[] { countryLocation });
    Targeting targeting = new Targeting();
    targeting.setInventoryTargeting(inventoryTargeting);
    targeting.setGeoTargeting(geoTargeting);
    TrafficForecastSegment segment = new TrafficForecastSegment();
    segment.setTargeting(targeting);
    segment.setName("Forecast segment #" + new Random().nextInt(Integer.MAX_VALUE));
    // Create the traffic forecst segment on the server.
    TrafficForecastSegment[] segments = adjustmentService.createTrafficForecastSegments(new TrafficForecastSegment[] { segment });
    for (TrafficForecastSegment createdSegment : segments) {
        System.out.printf("Traffic forecast segment with ID %d and %d forecast adjustments was created.%n", createdSegment.getId(), createdSegment.getActiveForecastAdjustmentCount());
    }
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface) TrafficForecastSegment(com.google.api.ads.admanager.axis.v202108.TrafficForecastSegment) AdUnitTargeting(com.google.api.ads.admanager.axis.v202108.AdUnitTargeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202108.AdUnitTargeting) Targeting(com.google.api.ads.admanager.axis.v202108.Targeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202108.InventoryTargeting) GeoTargeting(com.google.api.ads.admanager.axis.v202108.GeoTargeting) Random(java.util.Random) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202108.AdjustmentServiceInterface) InventoryTargeting(com.google.api.ads.admanager.axis.v202108.InventoryTargeting) GeoTargeting(com.google.api.ads.admanager.axis.v202108.GeoTargeting) Location(com.google.api.ads.admanager.axis.v202108.Location)

Example 10 with NetworkServiceInterface

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

the class AdvancedCreateCredentialFromScratch method runExample.

public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws Exception {
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Gets the current network.
    Network network = networkService.getCurrentNetwork();
    System.out.printf("Current network has network code '%s' and display name '%s'.%n", network.getNetworkCode(), network.getDisplayName());
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface) Network(com.google.api.ads.admanager.axis.v202205.Network)

Aggregations

Random (java.util.Random)24 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface)17 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface)15 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface)15 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface)15 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)7 InventoryTargeting (com.google.api.ads.admanager.axis.v202108.InventoryTargeting)7 AdUnitTargeting (com.google.api.ads.admanager.axis.v202111.AdUnitTargeting)7 InventoryTargeting (com.google.api.ads.admanager.axis.v202111.InventoryTargeting)7 AdUnitTargeting (com.google.api.ads.admanager.axis.v202202.AdUnitTargeting)7 InventoryTargeting (com.google.api.ads.admanager.axis.v202202.InventoryTargeting)7 AdUnitTargeting (com.google.api.ads.admanager.axis.v202205.AdUnitTargeting)7 InventoryTargeting (com.google.api.ads.admanager.axis.v202205.InventoryTargeting)7 Targeting (com.google.api.ads.admanager.axis.v202108.Targeting)6 Targeting (com.google.api.ads.admanager.axis.v202202.Targeting)6 Network (com.google.api.ads.admanager.axis.v202205.Network)6 Targeting (com.google.api.ads.admanager.axis.v202205.Targeting)6 Size (com.google.api.ads.admanager.axis.v202108.Size)5 Size (com.google.api.ads.admanager.axis.v202202.Size)5 Size (com.google.api.ads.admanager.axis.v202205.Size)5