Search in sources :

Example 6 with TrafficForecastSegment

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

the class GetAllTrafficForecastSegments 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 AdjustmentService.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    // Create a statement to get all traffic forecast segments.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get traffic forecast segments by statement.
        TrafficForecastSegmentPage page = adjustmentService.getTrafficForecastSegmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (TrafficForecastSegment trafficForecastSegment : page.getResults()) {
                System.out.printf("%d) Traffic forecast segment with ID %d and name '%s' was found.%n", i++, trafficForecastSegment.getId(), trafficForecastSegment.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : TrafficForecastSegment(com.google.api.ads.admanager.axis.v202202.TrafficForecastSegment) TrafficForecastSegmentPage(com.google.api.ads.admanager.axis.v202202.TrafficForecastSegmentPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface)

Example 7 with TrafficForecastSegment

use of com.google.api.ads.admanager.axis.v202205.TrafficForecastSegment 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.v202205.NetworkServiceInterface) TrafficForecastSegment(com.google.api.ads.admanager.axis.v202205.TrafficForecastSegment) AdUnitTargeting(com.google.api.ads.admanager.axis.v202205.AdUnitTargeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202205.AdUnitTargeting) Targeting(com.google.api.ads.admanager.axis.v202205.Targeting) GeoTargeting(com.google.api.ads.admanager.axis.v202205.GeoTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202205.InventoryTargeting) Random(java.util.Random) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202205.AdjustmentServiceInterface) InventoryTargeting(com.google.api.ads.admanager.axis.v202205.InventoryTargeting) GeoTargeting(com.google.api.ads.admanager.axis.v202205.GeoTargeting) Location(com.google.api.ads.admanager.axis.v202205.Location)

Example 8 with TrafficForecastSegment

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

the class GetAllTrafficForecastSegments 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 AdjustmentService.
    AdjustmentServiceInterface adjustmentService = adManagerServices.get(session, AdjustmentServiceInterface.class);
    // Create a statement to get all traffic forecast segments.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get traffic forecast segments by statement.
        TrafficForecastSegmentPage page = adjustmentService.getTrafficForecastSegmentsByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (TrafficForecastSegment trafficForecastSegment : page.getResults()) {
                System.out.printf("%d) Traffic forecast segment with ID %d and name '%s' was found.%n", i++, trafficForecastSegment.getId(), trafficForecastSegment.getName());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : TrafficForecastSegment(com.google.api.ads.admanager.axis.v202205.TrafficForecastSegment) TrafficForecastSegmentPage(com.google.api.ads.admanager.axis.v202205.TrafficForecastSegmentPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) AdjustmentServiceInterface(com.google.api.ads.admanager.axis.v202205.AdjustmentServiceInterface)

Aggregations

Random (java.util.Random)4 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202108.AdjustmentServiceInterface)2 TrafficForecastSegment (com.google.api.ads.admanager.axis.v202108.TrafficForecastSegment)2 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202111.AdjustmentServiceInterface)2 TrafficForecastSegment (com.google.api.ads.admanager.axis.v202111.TrafficForecastSegment)2 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202202.AdjustmentServiceInterface)2 TrafficForecastSegment (com.google.api.ads.admanager.axis.v202202.TrafficForecastSegment)2 AdjustmentServiceInterface (com.google.api.ads.admanager.axis.v202205.AdjustmentServiceInterface)2 TrafficForecastSegment (com.google.api.ads.admanager.axis.v202205.TrafficForecastSegment)2 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)1 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)1 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)1 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)1 AdUnitTargeting (com.google.api.ads.admanager.axis.v202108.AdUnitTargeting)1 GeoTargeting (com.google.api.ads.admanager.axis.v202108.GeoTargeting)1 InventoryTargeting (com.google.api.ads.admanager.axis.v202108.InventoryTargeting)1 Location (com.google.api.ads.admanager.axis.v202108.Location)1 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface)1 Targeting (com.google.api.ads.admanager.axis.v202108.Targeting)1 TrafficForecastSegmentPage (com.google.api.ads.admanager.axis.v202108.TrafficForecastSegmentPage)1