Search in sources :

Example 1 with Paging

use of com.google.api.ads.adwords.jaxws.v201809.cm.Paging in project googleads-java-lib by googleads.

the class SelectorBuilderImpl method build.

@Override
public Selector build() {
    Selector selectorCopy = new Selector();
    Set<OrderBy> orderingCopy = this.copyOrderingSet();
    Set<Predicate> predicatesCopy = this.copyPredicatesSet();
    selectorCopy.setFields(this.fields.toArray(new String[this.fields.size()]));
    selectorCopy.setOrdering(orderingCopy.toArray(new OrderBy[this.ordering.size()]));
    selectorCopy.setPredicates(predicatesCopy.toArray(new Predicate[this.predicates.size()]));
    if (this.dateRange != null) {
        selectorCopy.setDateRange(new DateRange(this.dateRange.getMin(), this.dateRange.getMax()));
    }
    if (this.paging != null) {
        selectorCopy.setPaging(new Paging(this.paging.getStartIndex(), this.paging.getNumberResults()));
    }
    return selectorCopy;
}
Also used : OrderBy(com.google.api.ads.adwords.axis.v201809.cm.OrderBy) DateRange(com.google.api.ads.adwords.axis.v201809.cm.DateRange) Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) Predicate(com.google.api.ads.adwords.axis.v201809.cm.Predicate)

Example 2 with Paging

use of com.google.api.ads.adwords.jaxws.v201809.cm.Paging in project googleads-java-lib by googleads.

the class GetKeywordIdeas method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the optional ID of the seed ad 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(AdWordsServicesInterface adWordsServices, AdWordsSession session, @Nullable Long adGroupId) throws RemoteException {
    // Get the TargetingIdeaService.
    TargetingIdeaServiceInterface targetingIdeaService = adWordsServices.get(session, TargetingIdeaServiceInterface.class);
    // Create selector.
    TargetingIdeaSelector selector = new TargetingIdeaSelector();
    selector.setRequestType(RequestType.IDEAS);
    selector.setIdeaType(IdeaType.KEYWORD);
    selector.setRequestedAttributeTypes(new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.AVERAGE_CPC, AttributeType.COMPETITION, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES });
    // Set selector paging (required for targeting idea service).
    Paging paging = new Paging();
    paging.setStartIndex(0);
    paging.setNumberResults(10);
    selector.setPaging(paging);
    List<SearchParameter> searchParameters = new ArrayList<>();
    // Create related to query search parameter.
    RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
    relatedToQuerySearchParameter.setQueries(new String[] { "bakery", "pastries", "birthday cake" });
    searchParameters.add(relatedToQuerySearchParameter);
    // Language setting (optional).
    // The ID can be found in the documentation:
    // https://developers.google.com/adwords/api/docs/appendix/languagecodes
    // See the documentation for limits on the number of allowed language parameters:
    // https://developers.google.com/adwords/api/docs/reference/latest/TargetingIdeaService.LanguageSearchParameter
    LanguageSearchParameter languageParameter = new LanguageSearchParameter();
    Language english = new Language();
    english.setId(1000L);
    languageParameter.setLanguages(new Language[] { english });
    searchParameters.add(languageParameter);
    // Create network search parameter (optional).
    NetworkSetting networkSetting = new NetworkSetting();
    networkSetting.setTargetGoogleSearch(true);
    networkSetting.setTargetSearchNetwork(false);
    networkSetting.setTargetContentNetwork(false);
    networkSetting.setTargetPartnerSearchNetwork(false);
    NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter();
    networkSearchParameter.setNetworkSetting(networkSetting);
    searchParameters.add(networkSearchParameter);
    // Optional: Use an existing ad group to generate ideas.
    if (adGroupId != null) {
        SeedAdGroupIdSearchParameter seedAdGroupIdSearchParameter = new SeedAdGroupIdSearchParameter();
        seedAdGroupIdSearchParameter.setAdGroupId(adGroupId);
        searchParameters.add(seedAdGroupIdSearchParameter);
    }
    selector.setSearchParameters(searchParameters.toArray(new SearchParameter[searchParameters.size()]));
    // Get keyword ideas.
    TargetingIdeaPage page = targetingIdeaService.get(selector);
    // Display keyword ideas.
    for (TargetingIdea targetingIdea : page.getEntries()) {
        Map<AttributeType, Attribute> data = Maps.toMap(targetingIdea.getData());
        StringAttribute keyword = (StringAttribute) data.get(AttributeType.KEYWORD_TEXT);
        IntegerSetAttribute categories = (IntegerSetAttribute) data.get(AttributeType.CATEGORY_PRODUCTS_AND_SERVICES);
        String categoriesString = "(none)";
        if (categories != null && categories.getValue() != null) {
            categoriesString = Joiner.on(", ").join(Ints.asList(categories.getValue()));
        }
        Long averageMonthlySearches = ((LongAttribute) data.get(AttributeType.SEARCH_VOLUME)).getValue();
        Money averageCpc = ((MoneyAttribute) data.get(AttributeType.AVERAGE_CPC)).getValue();
        Double competition = ((DoubleAttribute) data.get(AttributeType.COMPETITION)).getValue();
        System.out.printf("Keyword with text '%s', average monthly search volume %d, " + "average CPC %d, and competition %.2f " + "was found with categories: %s%n", keyword.getValue(), averageMonthlySearches, averageCpc.getMicroAmount(), competition, categoriesString);
    }
    if (page.getEntries() == null) {
        System.out.println("No related keywords were found.");
    }
}
Also used : SeedAdGroupIdSearchParameter(com.google.api.ads.adwords.axis.v201809.o.SeedAdGroupIdSearchParameter) TargetingIdea(com.google.api.ads.adwords.axis.v201809.o.TargetingIdea) DoubleAttribute(com.google.api.ads.adwords.axis.v201809.o.DoubleAttribute) Attribute(com.google.api.ads.adwords.axis.v201809.o.Attribute) LongAttribute(com.google.api.ads.adwords.axis.v201809.o.LongAttribute) MoneyAttribute(com.google.api.ads.adwords.axis.v201809.o.MoneyAttribute) StringAttribute(com.google.api.ads.adwords.axis.v201809.o.StringAttribute) IntegerSetAttribute(com.google.api.ads.adwords.axis.v201809.o.IntegerSetAttribute) ArrayList(java.util.ArrayList) StringAttribute(com.google.api.ads.adwords.axis.v201809.o.StringAttribute) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) TargetingIdeaPage(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaPage) AttributeType(com.google.api.ads.adwords.axis.v201809.o.AttributeType) LongAttribute(com.google.api.ads.adwords.axis.v201809.o.LongAttribute) MoneyAttribute(com.google.api.ads.adwords.axis.v201809.o.MoneyAttribute) LanguageSearchParameter(com.google.api.ads.adwords.axis.v201809.o.LanguageSearchParameter) NetworkSearchParameter(com.google.api.ads.adwords.axis.v201809.o.NetworkSearchParameter) SearchParameter(com.google.api.ads.adwords.axis.v201809.o.SearchParameter) RelatedToQuerySearchParameter(com.google.api.ads.adwords.axis.v201809.o.RelatedToQuerySearchParameter) SeedAdGroupIdSearchParameter(com.google.api.ads.adwords.axis.v201809.o.SeedAdGroupIdSearchParameter) TargetingIdeaSelector(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaSelector) Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) IntegerSetAttribute(com.google.api.ads.adwords.axis.v201809.o.IntegerSetAttribute) TargetingIdeaServiceInterface(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaServiceInterface) NetworkSearchParameter(com.google.api.ads.adwords.axis.v201809.o.NetworkSearchParameter) LanguageSearchParameter(com.google.api.ads.adwords.axis.v201809.o.LanguageSearchParameter) DoubleAttribute(com.google.api.ads.adwords.axis.v201809.o.DoubleAttribute) NetworkSetting(com.google.api.ads.adwords.axis.v201809.cm.NetworkSetting) RelatedToQuerySearchParameter(com.google.api.ads.adwords.axis.v201809.o.RelatedToQuerySearchParameter)

Example 3 with Paging

use of com.google.api.ads.adwords.jaxws.v201809.cm.Paging in project googleads-java-lib by googleads.

the class SelectorBuilderImpl method increaseOffsetBy.

@Override
public SelectorBuilderImpl increaseOffsetBy(int additionalOffset) {
    if (this.paging == null) {
        this.paging = new Paging();
    }
    Integer startIndex = paging.getStartIndex();
    if (startIndex == null) {
        startIndex = 0;
    }
    this.paging.setStartIndex(startIndex + additionalOffset);
    return this;
}
Also used : Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging)

Example 4 with Paging

use of com.google.api.ads.adwords.jaxws.v201809.cm.Paging 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 5 with Paging

use of com.google.api.ads.adwords.jaxws.v201809.cm.Paging in project googleads-java-lib by googleads.

the class SelectorBuilderTest method testUniqueInternalPagingState.

/**
 * Tests that the built selectors don't share internal Paging state.
 */
@Test
public void testUniqueInternalPagingState() {
    SelectorBuilder builder = new SelectorBuilder();
    Selector selectorOne = builder.fields("Id").offset(10).build();
    Selector selectorTwo = builder.fields("Status").offset(345).build();
    assertEquals(10, selectorOne.getPaging().getStartIndex().intValue());
    assertEquals(345, selectorTwo.getPaging().getStartIndex().intValue());
    checkUtilitiesState(false);
}
Also used : Selector(com.google.api.ads.adwords.jaxws.v201809.cm.Selector) Test(org.junit.Test)

Aggregations

Paging (com.google.api.ads.adwords.axis.v201809.cm.Paging)4 Selector (com.google.api.ads.adwords.jaxws.v201809.cm.Selector)3 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)2 Paging (com.google.api.ads.adwords.jaxws.v201809.cm.Paging)2 Test (org.junit.Test)2 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)1 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)1 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)1 DateRange (com.google.api.ads.adwords.axis.v201809.cm.DateRange)1 Language (com.google.api.ads.adwords.axis.v201809.cm.Language)1 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)1 NetworkSetting (com.google.api.ads.adwords.axis.v201809.cm.NetworkSetting)1 OrderBy (com.google.api.ads.adwords.axis.v201809.cm.OrderBy)1 Predicate (com.google.api.ads.adwords.axis.v201809.cm.Predicate)1 Attribute (com.google.api.ads.adwords.axis.v201809.o.Attribute)1 AttributeType (com.google.api.ads.adwords.axis.v201809.o.AttributeType)1 DoubleAttribute (com.google.api.ads.adwords.axis.v201809.o.DoubleAttribute)1 IntegerSetAttribute (com.google.api.ads.adwords.axis.v201809.o.IntegerSetAttribute)1 LanguageSearchParameter (com.google.api.ads.adwords.axis.v201809.o.LanguageSearchParameter)1 LongAttribute (com.google.api.ads.adwords.axis.v201809.o.LongAttribute)1