Search in sources :

Example 6 with Company

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

the class GetAdvertisers 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 {
    CompanyServiceInterface companyService = adManagerServices.get(session, CompanyServiceInterface.class);
    // Create a statement to select companies.
    StatementBuilder statementBuilder = new StatementBuilder().where("type = :type").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("type", CompanyType.ADVERTISER.toString());
    // Retrieve a small amount of companies at a time, paging through
    // until all companies have been retrieved.
    int totalResultSetSize = 0;
    do {
        CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.toStatement());
        if (page.getResults() != null) {
            // Print out some information for each company.
            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.v202111.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202111.Company) CompanyPage(com.google.api.ads.admanager.axis.v202111.CompanyPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)

Example 7 with Company

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

the class CreateCreativesFromTemplates 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.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long advertiserId) throws IOException {
    // Get the CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Create creative size.
    Size size = new Size();
    size.setWidth(600);
    size.setHeight(315);
    size.setIsAspectRatio(false);
    // Use the image banner with optional third party tracking template.
    // To determine what other creative templates exist,
    // run GetAllCreativeTemplates.java.
    long creativeTemplateId = 10000680L;
    // Create a template creative.
    TemplateCreative templateCreative = new TemplateCreative();
    templateCreative.setName("Template creative #" + new Random().nextInt(Integer.MAX_VALUE));
    templateCreative.setAdvertiserId(advertiserId);
    templateCreative.setCreativeTemplateId(creativeTemplateId);
    templateCreative.setSize(size);
    // Create the asset variable value.
    AssetCreativeTemplateVariableValue assetVariableValue = new AssetCreativeTemplateVariableValue();
    assetVariableValue.setUniqueName("Imagefile");
    CreativeAsset asset = new CreativeAsset();
    asset.setAssetByteArray(Media.getMediaDataFromUrl("https://goo.gl/3b9Wfh"));
    // Filenames must be unique.
    asset.setFileName(String.format("image%s.jpg", new Random().nextInt(Integer.MAX_VALUE)));
    assetVariableValue.setAsset(asset);
    // Create the image width variable value.
    LongCreativeTemplateVariableValue imageWidthVariableValue = new LongCreativeTemplateVariableValue();
    imageWidthVariableValue.setUniqueName("Imagewidth");
    imageWidthVariableValue.setValue(300L);
    // Create the image height variable value.
    LongCreativeTemplateVariableValue imageHeightVariableValue = new LongCreativeTemplateVariableValue();
    imageHeightVariableValue.setUniqueName("Imageheight");
    imageHeightVariableValue.setValue(250L);
    // Create the URL variable value.
    UrlCreativeTemplateVariableValue urlVariableValue = new UrlCreativeTemplateVariableValue();
    urlVariableValue.setUniqueName("ClickthroughURL");
    urlVariableValue.setValue("www.google.com");
    // Create the target window variable value.
    StringCreativeTemplateVariableValue targetWindowVariableValue = new StringCreativeTemplateVariableValue();
    targetWindowVariableValue.setUniqueName("Targetwindow");
    targetWindowVariableValue.setValue("__blank");
    // Set the creative template variables.
    templateCreative.setCreativeTemplateVariableValues(new BaseCreativeTemplateVariableValue[] { assetVariableValue, imageWidthVariableValue, imageHeightVariableValue, urlVariableValue, targetWindowVariableValue });
    // Create the creative on the server.
    Creative[] creatives = creativeService.createCreatives(new Creative[] { templateCreative });
    for (Creative createdCreative : creatives) {
        System.out.printf("A creative with ID %d, name '%s', and type '%s'" + " was created and can be previewed at: %s%n", createdCreative.getId(), createdCreative.getName(), createdCreative.getClass().getSimpleName(), createdCreative.getPreviewUrl());
    }
}
Also used : TemplateCreative(com.google.api.ads.admanager.axis.v202108.TemplateCreative) LongCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.LongCreativeTemplateVariableValue) Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202108.CreativeAsset) Creative(com.google.api.ads.admanager.axis.v202108.Creative) TemplateCreative(com.google.api.ads.admanager.axis.v202108.TemplateCreative) Size(com.google.api.ads.admanager.axis.v202108.Size) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface) StringCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.StringCreativeTemplateVariableValue) AssetCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.AssetCreativeTemplateVariableValue) UrlCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.UrlCreativeTemplateVariableValue)

Example 8 with Company

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

the class CreateNativeCreatives 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.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long advertiserId) throws IOException {
    // Get the CreativeService.
    CreativeServiceInterface creativeService = adManagerServices.get(session, CreativeServiceInterface.class);
    // Use the system defined native app install creative template.
    long nativeAppInstallTemplateId = 10004400L;
    // Use 1x1 as the size for native creatives.
    Size size = new Size();
    size.setWidth(1);
    size.setHeight(1);
    size.setIsAspectRatio(false);
    // Create a native app install creative for the Pie Noon app.
    TemplateCreative nativeAppInstallCreative = new TemplateCreative();
    nativeAppInstallCreative.setName("Native creative #" + new Random().nextInt(Integer.MAX_VALUE));
    nativeAppInstallCreative.setAdvertiserId(advertiserId);
    nativeAppInstallCreative.setDestinationUrl("https://play.google.com/store/apps/details?id=com.google.fpl.pie_noon");
    nativeAppInstallCreative.setCreativeTemplateId(nativeAppInstallTemplateId);
    nativeAppInstallCreative.setSize(size);
    List<BaseCreativeTemplateVariableValue> templateVariables = new ArrayList<>();
    // Set the headline.
    StringCreativeTemplateVariableValue headlineVariableValue = new StringCreativeTemplateVariableValue();
    headlineVariableValue.setUniqueName("Headline");
    headlineVariableValue.setValue("Pie Noon");
    templateVariables.add(headlineVariableValue);
    // Set the body text.
    StringCreativeTemplateVariableValue bodyVariableValue = new StringCreativeTemplateVariableValue();
    bodyVariableValue.setUniqueName("Body");
    bodyVariableValue.setValue("Try multi-screen mode!");
    templateVariables.add(bodyVariableValue);
    // Set the image asset.
    AssetCreativeTemplateVariableValue imageVariableValue = new AssetCreativeTemplateVariableValue();
    imageVariableValue.setUniqueName("Image");
    CreativeAsset imageAsset = new CreativeAsset();
    imageAsset.setFileName("image" + new Random().nextInt(Integer.MAX_VALUE) + ".png");
    imageAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://lh4.ggpht.com/" + "GIGNKdGHMEHFDw6TM2bgAUDKPQQRIReKZPqEpMeEhZOPYnTdOQGaSpGSEZflIFs0iw=h300"));
    imageVariableValue.setAsset(imageAsset);
    templateVariables.add(imageVariableValue);
    // Set the price.
    StringCreativeTemplateVariableValue priceVariableValue = new StringCreativeTemplateVariableValue();
    priceVariableValue.setUniqueName("Price");
    priceVariableValue.setValue("Free");
    templateVariables.add(priceVariableValue);
    // Set app icon image asset.
    AssetCreativeTemplateVariableValue appIconVariableValue = new AssetCreativeTemplateVariableValue();
    appIconVariableValue.setUniqueName("Appicon");
    CreativeAsset appIconAsset = new CreativeAsset();
    appIconAsset.setFileName("icon" + new Random().nextInt(Integer.MAX_VALUE) + ".png");
    appIconAsset.setAssetByteArray(Media.getMediaDataFromUrl("https://lh6.ggpht.com/" + "Jzvjne5CLs6fJ1MHF-XeuUfpABzl0YNMlp4RpHnvPRCIj4--eTDwtyouwUDzVVekXw=w300"));
    appIconVariableValue.setAsset(appIconAsset);
    templateVariables.add(appIconVariableValue);
    // Set the call to action text.
    StringCreativeTemplateVariableValue callToActionVariableValue = new StringCreativeTemplateVariableValue();
    callToActionVariableValue.setUniqueName("Calltoaction");
    callToActionVariableValue.setValue("Install");
    templateVariables.add(callToActionVariableValue);
    // Set the star rating.
    StringCreativeTemplateVariableValue starRatingVariableValue = new StringCreativeTemplateVariableValue();
    starRatingVariableValue.setUniqueName("Starrating");
    starRatingVariableValue.setValue("4");
    templateVariables.add(starRatingVariableValue);
    // Set the store type.
    StringCreativeTemplateVariableValue storeVariableValue = new StringCreativeTemplateVariableValue();
    storeVariableValue.setUniqueName("Store");
    storeVariableValue.setValue("Google Play");
    templateVariables.add(storeVariableValue);
    // Set the deep link URL.
    UrlCreativeTemplateVariableValue deepLinkVariableValue = new UrlCreativeTemplateVariableValue();
    deepLinkVariableValue.setUniqueName("DeeplinkclickactionURL");
    deepLinkVariableValue.setValue("market://details?id=com.google.fpl.pie_noon");
    templateVariables.add(deepLinkVariableValue);
    nativeAppInstallCreative.setCreativeTemplateVariableValues(templateVariables.toArray(new BaseCreativeTemplateVariableValue[templateVariables.size()]));
    // Create the creative on the server.
    Creative[] creatives = creativeService.createCreatives(new Creative[] { nativeAppInstallCreative });
    for (Creative createdCreative : creatives) {
        System.out.printf("A native creative with ID %d and name '%s' was" + " created and can be previewed at: %s%n", createdCreative.getId(), createdCreative.getName(), createdCreative.getPreviewUrl());
    }
}
Also used : TemplateCreative(com.google.api.ads.admanager.axis.v202108.TemplateCreative) Size(com.google.api.ads.admanager.axis.v202108.Size) ArrayList(java.util.ArrayList) StringCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.StringCreativeTemplateVariableValue) UrlCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.UrlCreativeTemplateVariableValue) Random(java.util.Random) CreativeAsset(com.google.api.ads.admanager.axis.v202108.CreativeAsset) Creative(com.google.api.ads.admanager.axis.v202108.Creative) TemplateCreative(com.google.api.ads.admanager.axis.v202108.TemplateCreative) CreativeServiceInterface(com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface) AssetCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.AssetCreativeTemplateVariableValue) BaseCreativeTemplateVariableValue(com.google.api.ads.admanager.axis.v202108.BaseCreativeTemplateVariableValue)

Example 9 with Company

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

Example 10 with Company

use of com.google.api.ads.admanager.axis.v202108.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.v202202.CompanyServiceInterface) Company(com.google.api.ads.admanager.axis.v202202.Company) CompanyPage(com.google.api.ads.admanager.axis.v202202.CompanyPage) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)

Aggregations

Random (java.util.Random)10 Company (com.google.api.ads.admanager.axis.v202202.Company)7 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202202.CompanyServiceInterface)7 AdManagerSession (com.google.api.ads.admanager.lib.client.AdManagerSession)6 Size (com.google.api.ads.admanager.axis.v202108.Size)5 MockHttpIntegrationTest (com.google.api.ads.common.lib.testing.MockHttpIntegrationTest)5 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)5 Test (org.junit.Test)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)4 Company (com.google.api.ads.admanager.axis.v202108.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202108.CompanyServiceInterface)4 Creative (com.google.api.ads.admanager.axis.v202108.Creative)4 CreativeAsset (com.google.api.ads.admanager.axis.v202108.CreativeAsset)4 CreativeServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeServiceInterface)4 Company (com.google.api.ads.admanager.axis.v202111.Company)4 CompanyServiceInterface (com.google.api.ads.admanager.axis.v202111.CompanyServiceInterface)4 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)4 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)4 Diff (org.xmlunit.diff.Diff)4 AdManagerServices (com.google.api.ads.admanager.axis.factory.AdManagerServices)3