Search in sources :

Example 16 with Campaign

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;
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)

Example 17 with Campaign

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);
}
Also used : Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) CampaignPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignPage) CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) ReportDownloadResponse(com.google.api.ads.adwords.lib.utils.ReportDownloadResponse) ReportDownloader(com.google.api.ads.adwords.lib.utils.v201809.ReportDownloader) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ReportDefinition(com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinition) ReportingConfiguration(com.google.api.ads.adwords.lib.client.reporting.ReportingConfiguration) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 18 with Campaign

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);
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup)

Example 19 with Campaign

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));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) CriterionError(com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError) Test(org.junit.Test)

Example 20 with Campaign

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));
}
Also used : BatchJobMutateResponse(com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse) BiddableAdGroupCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion) StreamSource(javax.xml.transform.stream.StreamSource) CriterionError(com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)23 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)15 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)15 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)11 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)9 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)9 Test (org.junit.Test)6 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)5 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)5 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)4 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)4 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)3 ManualCpcBiddingScheme (com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)3 ShoppingSetting (com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting)3 Campaign (com.google.api.ads.adwords.jaxws.v201809.cm.Campaign)3 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)2 DynamicSearchAdsSetting (com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting)2 GeoTargetTypeSetting (com.google.api.ads.adwords.axis.v201809.cm.GeoTargetTypeSetting)2