use of com.google.api.ads.admanager.axis.v202111.Company in project googleads-java-lib by googleads.
the class CreateLabels 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 LabelService.
LabelServiceInterface labelService = adManagerServices.get(session, LabelServiceInterface.class);
// Create a competitive exclusion label.
Label competitiveExclusionLabel = new Label();
competitiveExclusionLabel.setName("Car company label #" + new Random().nextInt(Integer.MAX_VALUE));
competitiveExclusionLabel.setTypes(new LabelType[] { LabelType.COMPETITIVE_EXCLUSION });
// Create an ad unit frequency cap label.
Label adUnitFrequencyCapLabel = new Label();
adUnitFrequencyCapLabel.setName("Don't run too often label #" + new Random().nextInt(Integer.MAX_VALUE));
adUnitFrequencyCapLabel.setTypes(new LabelType[] { LabelType.AD_UNIT_FREQUENCY_CAP });
// Create the labels on the server.
Label[] labels = labelService.createLabels(new Label[] { competitiveExclusionLabel, adUnitFrequencyCapLabel });
for (Label createdLabel : labels) {
System.out.printf("A label with ID %d and name '%s' was created.%n", createdLabel.getId(), createdLabel.getName());
}
}
use of com.google.api.ads.admanager.axis.v202111.Company in project googleads-java-lib by googleads.
the class AdManagerAxisSoapCompressionIntegrationTest method testGoldenSoap_oauth2.
/**
* Tests making a Axis Ad Manager API call with OAuth2 and compression enabled.
*/
@Test
public void testGoldenSoap_oauth2() throws Exception {
testHttpServer.setMockResponseBody(SoapResponseXmlProvider.getTestSoapResponse(API_VERSION));
GoogleCredential credential = new GoogleCredential.Builder().setTransport(new NetHttpTransport()).setJsonFactory(new JacksonFactory()).build();
credential.setAccessToken("TEST_ACCESS_TOKEN");
AdManagerSession session = new AdManagerSession.Builder().withApplicationName("TEST_APP").withOAuth2Credential(credential).withEndpoint(testHttpServer.getServerUrl()).withNetworkCode("TEST_NETWORK_CODE").build();
CompanyServiceInterface companyService = new AdManagerServices().get(session, CompanyServiceInterface.class);
Company[] companies = companyService.createCompanies(new Company[] { new Company() });
assertEquals(1234L, companies[0].getId().longValue());
assertTrue("Compression was enabled but the last request body was not compressed", testHttpServer.wasLastRequestBodyCompressed());
Diff diff = DiffBuilder.compare(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION)).withTest(testHttpServer.getLastRequestBody()).checkForSimilar().build();
assertFalse(diff.hasDifferences());
assertEquals("Bearer TEST_ACCESS_TOKEN", testHttpServer.getLastAuthorizationHttpHeader());
}
use of com.google.api.ads.admanager.axis.v202111.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);
}
use of com.google.api.ads.admanager.axis.v202111.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());
}
}
use of com.google.api.ads.admanager.axis.v202111.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());
}
}
Aggregations