use of com.google.api.ads.adwords.jaxws.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class BatchJobHelperTest method getPauseCampaignOperation.
@Override
protected Operation getPauseCampaignOperation(Long campaignId) {
CampaignOperation op = new CampaignOperation();
Campaign campaign = new Campaign();
campaign.setId(campaignId);
campaign.setStatus(CampaignStatus.PAUSED);
op.setOperand(campaign);
op.setOperator(Operator.SET);
return op;
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class AdvancedCreateCredentialFromScratch method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param reportFile the output file for the report contents.
* @throws DetailedReportDownloadResponseException if the report request failed with a detailed
* error from the reporting service.
* @throws ReportDownloadResponseException if the report request failed with a general error from
* the reporting service.
* @throws ReportException if the report request failed due to a transport layer error.
* @throws IOException if the report's contents could not be written to {@code reportFile}.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, String reportFile) throws ReportDownloadResponseException, ReportException, IOException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create selector to retrieve the first 100 campaigns.
Selector selector = new Selector();
selector.setFields(new String[] { "Id", "Name" });
Paging paging = new Paging();
paging.setStartIndex(0);
paging.setNumberResults(100);
// Get the first page of campaigns.
CampaignPage page = campaignService.get(selector);
System.out.printf("Found %d total campaigns.%n", page.getTotalNumEntries());
// Display campaigns.
if (page.getEntries() != null) {
for (Campaign campaign : page.getEntries()) {
System.out.printf("Campaign with name '%s' and ID %d was found.%n", campaign.getName(), campaign.getId());
}
} else {
System.out.println("No campaigns were found.");
}
// Create selector.
com.google.api.ads.adwords.lib.jaxb.v201809.Selector reportSelector = new com.google.api.ads.adwords.lib.jaxb.v201809.Selector();
reportSelector.getFields().addAll(Arrays.asList("CampaignId", "AdGroupId", "Id", "CriteriaType", "Criteria", "Impressions", "Clicks", "Cost"));
// Create report definition.
ReportDefinition reportDefinition = new ReportDefinition();
reportDefinition.setReportName("Criteria performance report #" + System.currentTimeMillis());
reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.YESTERDAY);
reportDefinition.setReportType(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT);
reportDefinition.setDownloadFormat(DownloadFormat.CSV);
reportDefinition.setSelector(reportSelector);
ReportingConfiguration reportingConfig = new ReportingConfiguration.Builder().includeZeroImpressions(false).build();
session.setReportingConfiguration(reportingConfig);
ReportDownloadResponse response = new ReportDownloader(session).downloadReport(reportDefinition);
FileOutputStream fos = new FileOutputStream(new File(reportFile));
Streams.copy(response.getInputStream(), fos);
fos.close();
System.out.printf("Report successfully downloaded: %s%n", reportFile);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method runExample.
/**
* Runs the example.
*
* @param adWordsServices 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(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
Budget budget = createBudget(adWordsServices, session);
Campaign campaign = createCampaign(adWordsServices, session, budget);
AdGroup adGroup = createAdGroup(adWordsServices, session, campaign);
createExpandedDSA(adWordsServices, session, adGroup);
addWebPageCriteria(adWordsServices, session, adGroup);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class JaxWsBatchJobResponseDeserializerTest method testDeserializeBatchJobMutateResponseWithErrors.
@Test
public void testDeserializeBatchJobMutateResponseWithErrors() throws Exception {
BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, JaxWsBatchJobResponseDeserializerTest.class.getResource("resources/BatchJobMutate.responseWithErrors.xml"));
assertNotNull("Null deserialized request returned", response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
// CriterionError, CriterionError, CriterionError
assertEquals(7, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class JaxWsDeserializationTest method testDeserializeBatchJobMutateRequest.
@Test
public void testDeserializeBatchJobMutateRequest() {
Source source = new StreamSource(JaxWsDeserializationTest.class.getResourceAsStream("resources/BatchJobMutate.responseWithErrors.xml"));
BatchJobMutateResponse response = deserializer.deserialize(source);
assertNotNull("Null deserialized request returned", response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion,
// CriterionError, CriterionError, CriterionError
assertEquals(7, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[2].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertThat(response.getMutateResults()[4].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[5].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
assertThat(response.getMutateResults()[6].getErrorList().getErrors()[0], Matchers.instanceOf(CriterionError.class));
}
Aggregations