use of com.google.api.ads.admanager.axis.v202205.Network 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());
}
}
use of com.google.api.ads.admanager.axis.v202205.Network 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());
}
}
use of com.google.api.ads.admanager.axis.v202205.Network in project googleads-java-lib by googleads.
the class MakeTestNetwork 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 NetworkService.
NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
// Make the test network.
Network network = networkService.makeTestNetwork();
System.out.printf("Test network with network code '%s' and display name '%s' created.%n" + "You may now sign in at https://admanager.google.com/%s%n", network.getNetworkCode(), network.getDisplayName(), network.getNetworkCode());
}
use of com.google.api.ads.admanager.axis.v202205.Network in project googleads-java-lib by googleads.
the class GetAllNetworks 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 NetworkService.
NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
// Get all networks that you have access to with the current authentication
// credentials.
Network[] networks = networkService.getAllNetworks();
int i = 0;
for (Network network : networks) {
System.out.printf("%d) Network with network code '%s' and display name '%s' was found.%n", i++, network.getNetworkCode(), network.getDisplayName());
}
System.out.printf("Number of networks found: %d%n", networks.length);
}
Aggregations