Search in sources :

Example 1 with Site

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

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

Example 2 with Site

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

the class CreateSites method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param childNetworkCode the child network code of the site.
 * @param url the URL of the site.
 * @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, String childNetworkCode, String url) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Validate that the site can be created.
    Network currentNetwork = networkService.getCurrentNetwork();
    ChildPublisher childNetwork = null;
    for (ChildPublisher child : currentNetwork.getChildPublishers()) {
        if (childNetworkCode.equals(child.getChildNetworkCode())) {
            childNetwork = child;
            break;
        }
    }
    if (childNetwork == null) {
        throw new IllegalStateException(String.format("Child network %s not found on the current network (%s). Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    if (!DelegationType.MANAGE_INVENTORY.equals(childNetwork.getApprovedDelegationType())) {
        throw new IllegalStateException(String.format("Child network %s has not approved the current network (%s) to manage its inventory." + " Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    // Create a site.
    Site site = new Site();
    site.setChildNetworkCode(childNetworkCode);
    site.setUrl(url);
    // Create the site on the server.
    Site[] sites = siteService.createSites(new Site[] { site });
    for (Site createdSite : sites) {
        System.out.printf("A site with ID %d and URL '%s' was created.%n", createdSite.getId(), createdSite.getUrl());
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202111.Site) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface) SiteServiceInterface(com.google.api.ads.admanager.axis.v202111.SiteServiceInterface) ChildPublisher(com.google.api.ads.admanager.axis.v202111.ChildPublisher) Network(com.google.api.ads.admanager.axis.v202111.Network)

Example 3 with Site

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

the class GetAllSites 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 SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Create a statement to get all sites.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get sites by statement.
        SitePage page = siteService.getSitesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Site site : page.getResults()) {
                System.out.printf("%d) Site with ID %d and URL '%s' was found.%n", i++, site.getId(), site.getUrl());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : Site(com.google.api.ads.admanager.axis.v202108.Site) SitePage(com.google.api.ads.admanager.axis.v202108.SitePage) SiteServiceInterface(com.google.api.ads.admanager.axis.v202108.SiteServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)

Example 4 with Site

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

the class CreateSites method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param childNetworkCode the child network code of the site.
 * @param url the URL of the site.
 * @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, String childNetworkCode, String url) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Validate that the site can be created.
    Network currentNetwork = networkService.getCurrentNetwork();
    ChildPublisher childNetwork = null;
    for (ChildPublisher child : currentNetwork.getChildPublishers()) {
        if (childNetworkCode.equals(child.getChildNetworkCode())) {
            childNetwork = child;
            break;
        }
    }
    if (childNetwork == null) {
        throw new IllegalStateException(String.format("Child network %s not found on the current network (%s). Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    if (!DelegationType.MANAGE_INVENTORY.equals(childNetwork.getApprovedDelegationType())) {
        throw new IllegalStateException(String.format("Child network %s has not approved the current network (%s) to manage its inventory." + " Cannot create site.", childNetworkCode, currentNetwork.getNetworkCode()));
    }
    // Create a site.
    Site site = new Site();
    site.setChildNetworkCode(childNetworkCode);
    site.setUrl(url);
    // Create the site on the server.
    Site[] sites = siteService.createSites(new Site[] { site });
    for (Site createdSite : sites) {
        System.out.printf("A site with ID %d and URL '%s' was created.%n", createdSite.getId(), createdSite.getUrl());
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202108.Site) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202108.NetworkServiceInterface) SiteServiceInterface(com.google.api.ads.admanager.axis.v202108.SiteServiceInterface) ChildPublisher(com.google.api.ads.admanager.axis.v202108.ChildPublisher) Network(com.google.api.ads.admanager.axis.v202108.Network)

Example 5 with Site

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

the class GetTrafficData method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param advertiserId the ID of the advertiser (company) to forecast for. Setting an advertiser
 *     will cause the forecast to apply the appropriate unified blocking rules.
 * @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 ForecastService.
    ForecastServiceInterface forecastService = adManagerServices.get(session, ForecastServiceInterface.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.
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId(rootAdUnitId);
    adUnitTargeting.setIncludeDescendants(true);
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { adUnitTargeting });
    // Create targeting.
    Targeting targeting = new Targeting();
    targeting.setInventoryTargeting(inventoryTargeting);
    // Create the date range. Include the previous and next 7 days.
    Interval interval = new Interval(Instant.now().plus(Duration.standardDays(-7)), Instant.now().plus(Duration.standardDays(7)));
    DateRange dateRange = new DateRange();
    dateRange.setStartDate(DateTimes.toDateTime(interval.getStart()).getDate());
    dateRange.setEndDate(DateTimes.toDateTime(interval.getEnd()).getDate());
    // Request the traffic data.
    TrafficDataRequest trafficDataRequest = new TrafficDataRequest();
    trafficDataRequest.setRequestedDateRange(dateRange);
    trafficDataRequest.setTargeting(targeting);
    TrafficDataResponse trafficData = forecastService.getTrafficData(trafficDataRequest);
    // Read the historical traffic data.
    TimeSeries historicalTimeSeries = trafficData.getHistoricalTimeSeries();
    if (historicalTimeSeries != null) {
        Date historicalStartDate = historicalTimeSeries.getTimeSeriesDateRange().getStartDate();
        DateTime historicalStart = new DateTime(historicalStartDate.getYear(), historicalStartDate.getMonth(), historicalStartDate.getDay(), 0, 0, 0);
        for (int i = 0; i < historicalTimeSeries.getValues().length; i++) {
            System.out.printf("%s: %d historical ad opportunities%n", historicalStart.plus(Duration.standardDays(i)).toString(DateTimeFormat.longDate()), historicalTimeSeries.getValues()[i]);
        }
    }
    // Read the forecasted traffic data.
    TimeSeries forecastedTimeSeries = trafficData.getForecastedTimeSeries();
    if (forecastedTimeSeries != null) {
        Date forecastedStartDate = forecastedTimeSeries.getTimeSeriesDateRange().getStartDate();
        DateTime forecastedStart = new DateTime(forecastedStartDate.getYear(), forecastedStartDate.getMonth(), forecastedStartDate.getDay(), 0, 0, 0);
        for (int i = 0; i < forecastedTimeSeries.getValues().length; i++) {
            System.out.printf("%s: %d forecasted ad opportunities%n", forecastedStart.plus(Duration.standardDays(i)).toString(DateTimeFormat.longDate()), forecastedTimeSeries.getValues()[i]);
        }
    }
}
Also used : TrafficDataResponse(com.google.api.ads.admanager.axis.v202202.TrafficDataResponse) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) TimeSeries(com.google.api.ads.admanager.axis.v202202.TimeSeries) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) Targeting(com.google.api.ads.admanager.axis.v202202.Targeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202202.InventoryTargeting) Date(com.google.api.ads.admanager.axis.v202202.Date) DateTime(org.joda.time.DateTime) ForecastServiceInterface(com.google.api.ads.admanager.axis.v202202.ForecastServiceInterface) DateRange(com.google.api.ads.admanager.axis.v202202.DateRange) AdUnitTargeting(com.google.api.ads.admanager.axis.v202202.AdUnitTargeting) TrafficDataRequest(com.google.api.ads.admanager.axis.v202202.TrafficDataRequest) Interval(org.joda.time.Interval)

Aggregations

NetworkServiceInterface (com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface)8 AdUnitTargeting (com.google.api.ads.admanager.axis.v202202.AdUnitTargeting)7 InventoryTargeting (com.google.api.ads.admanager.axis.v202202.InventoryTargeting)7 Targeting (com.google.api.ads.admanager.axis.v202202.Targeting)6 Random (java.util.Random)5 Site (com.google.api.ads.admanager.axis.v202108.Site)4 SiteServiceInterface (com.google.api.ads.admanager.axis.v202108.SiteServiceInterface)4 Site (com.google.api.ads.admanager.axis.v202111.Site)4 SiteServiceInterface (com.google.api.ads.admanager.axis.v202111.SiteServiceInterface)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202202.CreativePlaceholder)4 Goal (com.google.api.ads.admanager.axis.v202202.Goal)4 Site (com.google.api.ads.admanager.axis.v202202.Site)4 SiteServiceInterface (com.google.api.ads.admanager.axis.v202202.SiteServiceInterface)4 Size (com.google.api.ads.admanager.axis.v202202.Size)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)3 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)3 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)3 SitePage (com.google.api.ads.admanager.axis.v202108.SitePage)3 SitePage (com.google.api.ads.admanager.axis.v202111.SitePage)3 SitePage (com.google.api.ads.admanager.axis.v202202.SitePage)3