Search in sources :

Example 36 with Company

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

the class CreateActivityGroups method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param advertiserCompanyId the ID of the company for the activity group.
 * @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 advertiserCompanyId) throws RemoteException {
    // Get the ActivityGroupService.
    ActivityGroupServiceInterface activityGroupService = adManagerServices.get(session, ActivityGroupServiceInterface.class);
    // Create a short-term activity group.
    ActivityGroup shortTermActivityGroup = new ActivityGroup();
    shortTermActivityGroup.setName("Short-term activity group #" + new Random().nextInt(Integer.MAX_VALUE));
    shortTermActivityGroup.setCompanyIds(new long[] { advertiserCompanyId });
    shortTermActivityGroup.setClicksLookback(1);
    shortTermActivityGroup.setImpressionsLookback(1);
    // Create a long-term activity group.
    ActivityGroup longTermActivityGroup = new ActivityGroup();
    longTermActivityGroup.setName("Long-term activity group #" + new Random().nextInt(Integer.MAX_VALUE));
    longTermActivityGroup.setCompanyIds(new long[] { advertiserCompanyId });
    longTermActivityGroup.setClicksLookback(30);
    longTermActivityGroup.setImpressionsLookback(30);
    // Create the activity groups on the server.
    ActivityGroup[] activityGroups = activityGroupService.createActivityGroups(new ActivityGroup[] { shortTermActivityGroup, longTermActivityGroup });
    for (ActivityGroup createdActivityGroup : activityGroups) {
        System.out.printf("An activity group with ID %d and name '%s' was created.%n", createdActivityGroup.getId(), createdActivityGroup.getName());
    }
}
Also used : Random(java.util.Random) ActivityGroupServiceInterface(com.google.api.ads.admanager.axis.v202205.ActivityGroupServiceInterface) ActivityGroup(com.google.api.ads.admanager.axis.v202205.ActivityGroup)

Example 37 with Company

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

the class CreateCompanies 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 CompanyService.
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create an advertiser.
    Company advertiser = new Company();
    advertiser.setName("Advertiser #" + new Random().nextInt(Integer.MAX_VALUE));
    advertiser.setType(CompanyType.ADVERTISER);
    // Create an agency.
    Company agency = new Company();
    agency.setName("Agency #" + new Random().nextInt(Integer.MAX_VALUE));
    agency.setType(CompanyType.AGENCY);
    // Create the companies on the server.
    Company[] companies = companyService.createCompanies(new Company[] { advertiser, agency });
    for (Company createdCompany : companies) {
        System.out.printf("A company with ID %d, name '%s', and type '%s' was created.%n", createdCompany.getId(), createdCompany.getName(), createdCompany.getType());
    }
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202205.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202205.Company) Random(java.util.Random)

Example 38 with Company

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

the class GetAllCompanies 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 CompanyService.
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create a statement to get all companies.
    StatementBuilder statementBuilder = new StatementBuilder().orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    int totalResultSetSize = 0;
    do {
        // Get companies by statement.
        CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            totalResultSetSize = page.getTotalResultSetSize();
            int i = page.getStartIndex();
            for (Company company : page.getResults()) {
                System.out.printf("%d) Company with ID %d, name '%s', and type '%s' was found.%n", i++, company.getId(), company.getName(), company.getType());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of results found: %d%n", totalResultSetSize);
}
Also used : CompanyServiceInterface(com.google.api.ads.admanager.axis.v202205.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202205.Company) CompanyPage(com.google.api.ads.admanager.axis.v202205.CompanyPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)

Example 39 with Company

use of com.google.api.ads.admanager.axis.v202205.Company 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.v202205.TrafficDataResponse) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface) TimeSeries(com.google.api.ads.admanager.axis.v202205.TimeSeries) AdUnitTargeting(com.google.api.ads.admanager.axis.v202205.AdUnitTargeting) Targeting(com.google.api.ads.admanager.axis.v202205.Targeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202205.InventoryTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202205.InventoryTargeting) Date(com.google.api.ads.admanager.axis.v202205.Date) DateTime(org.joda.time.DateTime) ForecastServiceInterface(com.google.api.ads.admanager.axis.v202205.ForecastServiceInterface) DateRange(com.google.api.ads.admanager.axis.v202205.DateRange) AdUnitTargeting(com.google.api.ads.admanager.axis.v202205.AdUnitTargeting) TrafficDataRequest(com.google.api.ads.admanager.axis.v202205.TrafficDataRequest) Interval(org.joda.time.Interval)

Example 40 with Company

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

the class CreateOrders method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param advertiserId the ID of the advertiser (company) that all creatives will be assigned to.
 * @param traffickerId the ID of the trafficker (user) associated with this order.
 * @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 advertiserId, long traffickerId) throws RemoteException {
    // Get the OrderService.
    OrderServiceInterface orderService = adManagerServices.get(session, OrderServiceInterface.class);
    // Create an order.
    Order order = new Order();
    order.setName("Order #" + new Random().nextInt(Integer.MAX_VALUE));
    order.setAdvertiserId(advertiserId);
    order.setTraffickerId(traffickerId);
    // Create the order on the server.
    Order[] orders = orderService.createOrders(new Order[] { order });
    for (Order createdOrder : orders) {
        System.out.printf("An order with ID %d and name '%s' was created.%n", createdOrder.getId(), createdOrder.getName());
    }
}
Also used : Order(com.google.api.ads.admanager.axis.v202205.Order) Random(java.util.Random) OrderServiceInterface(com.google.api.ads.admanager.axis.v202205.OrderServiceInterface)

Aggregations

Random (java.util.Random)12 Test (org.junit.Test)11 Company (com.google.cloud.talent.v4beta1.Company)10 Company (com.google.api.ads.admanager.axis.v202205.Company)7 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202205.CompanyServiceInterface)7 Size (com.google.api.ads.admanager.axis.v202205.Size)6 CompanyServiceClient (com.google.cloud.talent.v4beta1.CompanyServiceClient)6 AdManagerSession (com.google.api.ads.admanager.lib.client.AdManagerSession)5 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)5 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)4 Company (com.google.api.ads.admanager.axis.v202108.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202108.CompanyServiceInterface)4 Company (com.google.api.ads.admanager.axis.v202111.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface)4 Company (com.google.api.ads.admanager.axis.v202202.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202202.CompanyServiceInterface)4 Creative (com.google.api.ads.admanager.axis.v202205.Creative)4 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202205.CreativeServiceInterface)4 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)4