hi,
   I used Google ads api to get the report data, but I encountered a paging 
problem
    
  How to understand the two things: limit in SQL and setPageSize in request

  The first request page token is empty, limit 2000 returned 2000 When the 
second request page token was passed, the next page token returned for the 
first time, limit 2000 returned 1000 data, and the next page token returned 
empty, so it ended.
Because two requests were sent, the data after deduplication was 2000。 

What should I do if I want to get data in pages??

here is my code:

public String getCampaignReport(String customerId, int size, String 
pageToken) {

    // Creates a request that will retrieve all campaigns using pages of the 
specified page size.

    String query = "SELECT customer.id, "

        + "campaign.id, "
        + "campaign.name, "
        + "segments.ad_network_type, segments.date,"
        + "metrics.impressions, "
        + "metrics.clicks, metrics.average_cost, metrics.interactions,"
        + "metrics.cost_per_conversion "
        + "FROM campaign where segments.date BETWEEN '2018-10-10' AND 
'2020-04-12'";

    if (size > 0) {
        query = query + " LIMIT " + size;
    }

    log.info("pageToken {} , query sql {}", pageToken, query);
    SearchGoogleAdsRequest.Builder builder =
        SearchGoogleAdsRequest.newBuilder()
            .setCustomerId(customerId)
            .setPageSize(1000)
            .setQuery(query);

    if (!Strings.isNullOrEmpty(pageToken)) {
        builder.setPageToken(pageToken);
    }
    // Issues the search request.
    SearchPagedResponse searchPagedResponse = 
googleAdsServiceClient.search(builder.build());
    if (searchPagedResponse == null) {
        log.info("searchPagedResponse null");
        return "";
    }

    List<Long> sizeList = Lists.newLinkedList();
    Set<Long> sizeSet = Sets.newHashSet();
    // Iterates over all rows in all pages and prints the requested field 
values for the campaign
    // in each row.
    for (GoogleAdsRow googleAdsRow : searchPagedResponse.iterateAll()) {
        Campaign campaign = googleAdsRow.getCampaign();
        Segments segments = googleAdsRow.getSegments();
        Metrics metrics = googleAdsRow.getMetrics();
        log.info("Campaign with ID {} and name {} was found. "
                + "segments date {}, network_type {}"
                + "Campaign {}, {}, {}, {}, {}, {}",
            campaign.getId().getValue(), campaign.getName().getValue(),
            segments.getDate().getValue(), segments.getAdNetworkType(),
            metrics.getImpressions().getValue(), metrics.getClicks().getValue(),
            metrics.getCostPerConversion().getValue(),
            metrics.getAverageCost().getValue(), 
metrics.getInteractions().getValue(),
            metrics.getAverageCost().getValue() * 
metrics.getInteractions().getValue());

        sizeList.add(campaign.getId().getValue());
        sizeSet.add(campaign.getId().getValue());
    }

    log.info("list size {}, set size {}, next page token {}", sizeList.size(), 
sizeSet.size(), searchPagedResponse.getNextPageToken());
    return searchPagedResponse.getNextPageToken();
}

public void getAllCampaignReport(String customerId, int size) {

    String nextPageToken = getCampaignReport(customerId, size, null);
    while (!Strings.isNullOrEmpty(nextPageToken)) {
        nextPageToken = getCampaignReport(customerId, size, nextPageToken);
    }
}

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/9010763a-34f6-47d4-969f-929ae3631186%40googlegroups.com.

Reply via email to