use of com.google.api.ads.admanager.axis.v202205.SiteServiceInterface 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);
}
use of com.google.api.ads.admanager.axis.v202205.SiteServiceInterface 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);
}
use of com.google.api.ads.admanager.axis.v202205.SiteServiceInterface 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.v202111.SubmitSiteForApproval action = new com.google.api.ads.admanager.axis.v202111.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.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.SiteServiceInterface 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.v202202.SubmitSiteForApproval action = new com.google.api.ads.admanager.axis.v202202.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.");
}
}
}
use of com.google.api.ads.admanager.axis.v202205.SiteServiceInterface 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());
}
}
Aggregations