Search in sources :

Example 1 with Site

use of com.google.api.ads.admanager.axis.v202205.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 2 with Site

use of com.google.api.ads.admanager.axis.v202205.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 3 with Site

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

the class CreateProposalLineItems method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param proposalId the ID of the proposal that the proposal line items will belong 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.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session, long proposalId) throws RemoteException {
    ProposalLineItemServiceInterface proposalLineItemService = adManagerServices.get(session, ProposalLineItemServiceInterface.class);
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    ProposalLineItem proposalLineItem = new ProposalLineItem();
    // Set common required fields for a proposal line item.
    proposalLineItem.setName("Proposal line item #" + new Random().nextInt(Integer.MAX_VALUE));
    proposalLineItem.setProposalId(proposalId);
    proposalLineItem.setLineItemType(LineItemType.STANDARD);
    // 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 });
    // Target display environment
    RequestPlatformTargeting requestPlatformTargeting = new RequestPlatformTargeting();
    requestPlatformTargeting.setTargetedRequestPlatforms(new RequestPlatform[] { RequestPlatform.BROWSER });
    // Target Display environment by excluding Mobile Apps.
    // DeviceCapabilities can be obtained though the Device_Capability PQL table:
    // https://developers.google.com/ad-manager/api/reference/latest/PublisherQueryLanguageService
    DeviceCapability mobileApps = new DeviceCapability();
    mobileApps.setId(5005L);
    DeviceCapabilityTargeting deviceCapabilityTargeting = new DeviceCapabilityTargeting();
    deviceCapabilityTargeting.setExcludedDeviceCapabilities(new DeviceCapability[] { mobileApps });
    TechnologyTargeting technologyTargeting = new TechnologyTargeting();
    technologyTargeting.setDeviceCapabilityTargeting(deviceCapabilityTargeting);
    // Create targeting.
    Targeting targeting = new Targeting();
    targeting.setInventoryTargeting(inventoryTargeting);
    targeting.setRequestPlatformTargeting(requestPlatformTargeting);
    targeting.setTechnologyTargeting(technologyTargeting);
    proposalLineItem.setTargeting(targeting);
    // Create creative placeholder size.
    Size size = new Size();
    size.setWidth(300);
    size.setHeight(250);
    size.setIsAspectRatio(false);
    // Create the creative placeholder.
    CreativePlaceholder creativePlaceholder = new CreativePlaceholder();
    creativePlaceholder.setSize(size);
    // Set the size of creatives that can be associated with this proposal line item.
    proposalLineItem.setCreativePlaceholders(new CreativePlaceholder[] { creativePlaceholder });
    // Set the length of the proposal line item to run.
    proposalLineItem.setStartDateTime(DateTimes.toDateTime(Instant.now(), "America/New_York"));
    proposalLineItem.setEndDateTime(DateTimes.toDateTime(Instant.now().plus(Duration.standardDays(30L)), "America/New_York"));
    // Set delivery specifications for the proposal line item.
    proposalLineItem.setDeliveryRateType(DeliveryRateType.EVENLY);
    // Set pricing for the proposal line item for 1000 impressions at a CPM of $2
    // for a total value of $2.
    Goal goal = new Goal();
    goal.setUnits(1000L);
    goal.setUnitType(UnitType.IMPRESSIONS);
    proposalLineItem.setGoal(goal);
    proposalLineItem.setNetRate(new Money("USD", 2000000L));
    proposalLineItem.setRateType(RateType.CPM);
    ProposalLineItem[] proposalLineItems = proposalLineItemService.createProposalLineItems(new ProposalLineItem[] { proposalLineItem });
    for (ProposalLineItem createdProposalLineItem : proposalLineItems) {
        System.out.printf("A proposal line item with ID %d and name '%s' was created.%n", createdProposalLineItem.getId(), createdProposalLineItem.getName());
    }
}
Also used : DeviceCapabilityTargeting(com.google.api.ads.admanager.axis.v202205.DeviceCapabilityTargeting) NetworkServiceInterface(com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface) RequestPlatformTargeting(com.google.api.ads.admanager.axis.v202205.RequestPlatformTargeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202205.AdUnitTargeting) DeviceCapabilityTargeting(com.google.api.ads.admanager.axis.v202205.DeviceCapabilityTargeting) RequestPlatformTargeting(com.google.api.ads.admanager.axis.v202205.RequestPlatformTargeting) Targeting(com.google.api.ads.admanager.axis.v202205.Targeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202205.InventoryTargeting) TechnologyTargeting(com.google.api.ads.admanager.axis.v202205.TechnologyTargeting) Size(com.google.api.ads.admanager.axis.v202205.Size) InventoryTargeting(com.google.api.ads.admanager.axis.v202205.InventoryTargeting) CreativePlaceholder(com.google.api.ads.admanager.axis.v202205.CreativePlaceholder) Money(com.google.api.ads.admanager.axis.v202205.Money) Goal(com.google.api.ads.admanager.axis.v202205.Goal) AdUnitTargeting(com.google.api.ads.admanager.axis.v202205.AdUnitTargeting) Random(java.util.Random) ProposalLineItem(com.google.api.ads.admanager.axis.v202205.ProposalLineItem) TechnologyTargeting(com.google.api.ads.admanager.axis.v202205.TechnologyTargeting) ProposalLineItemServiceInterface(com.google.api.ads.admanager.axis.v202205.ProposalLineItemServiceInterface) DeviceCapability(com.google.api.ads.admanager.axis.v202205.DeviceCapability)

Example 4 with Site

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

the class GetSitesRequiringApproval 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 select sites needing approval.
    StatementBuilder statementBuilder = new StatementBuilder().where("approvalStatus = :approvalStatus").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("approvalStatus", ApprovalStatus.REQUIRES_REVIEW.toString());
    // 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.v202205.Site) SitePage(com.google.api.ads.admanager.axis.v202205.SitePage) SiteServiceInterface(com.google.api.ads.admanager.axis.v202205.SiteServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)

Example 5 with Site

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

the class SubmitSiteForApproval method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @param siteId the ID of the site to submit for approval.
 * @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 siteId) throws RemoteException {
    // Get the SiteService.
    SiteServiceInterface siteService = adManagerServices.get(session, SiteServiceInterface.class);
    // Create a statement to select a site.
    StatementBuilder statementBuilder = new StatementBuilder().where("WHERE id = :id").orderBy("id ASC").limit(StatementBuilder.SUGGESTED_PAGE_LIMIT).withBindVariableValue("id", siteId);
    // 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 will be submitted for approval.%n", i++, site.getId());
            }
        }
        statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);
    System.out.printf("Number of sites to be submitted: %d%n", totalResultSetSize);
    if (totalResultSetSize > 0) {
        // Remove limit and offset from statement.
        statementBuilder.removeLimitAndOffset();
        // Create action.
        com.google.api.ads.admanager.axis.v202205.SubmitSiteForApproval action = new com.google.api.ads.admanager.axis.v202205.SubmitSiteForApproval();
        // Perform action.
        UpdateResult result = siteService.performSiteAction(action, statementBuilder.toStatement());
        if (result != null && result.getNumChanges() > 0) {
            System.out.printf("Number of sites submitted: %d%n", result.getNumChanges());
        } else {
            System.out.println("No sites were submitted.");
        }
    }
}
Also used : Site(com.google.api.ads.admanager.axis.v202205.Site) SitePage(com.google.api.ads.admanager.axis.v202205.SitePage) SiteServiceInterface(com.google.api.ads.admanager.axis.v202205.SiteServiceInterface) StatementBuilder(com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder) UpdateResult(com.google.api.ads.admanager.axis.v202205.UpdateResult)

Aggregations

NetworkServiceInterface (com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface)8 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.v202205.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 Site (com.google.api.ads.admanager.axis.v202202.Site)4 SiteServiceInterface (com.google.api.ads.admanager.axis.v202202.SiteServiceInterface)4 CreativePlaceholder (com.google.api.ads.admanager.axis.v202205.CreativePlaceholder)4 Goal (com.google.api.ads.admanager.axis.v202205.Goal)4 Site (com.google.api.ads.admanager.axis.v202205.Site)4 SiteServiceInterface (com.google.api.ads.admanager.axis.v202205.SiteServiceInterface)4 Size (com.google.api.ads.admanager.axis.v202205.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 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202205.StatementBuilder)3