Google Ads API V10 Search Stream always returns 10 records only

655 views
Skip to first unread message

Moideen Shihab Vaisyar Kandi

unread,
Mar 21, 2022, 5:59:37 AM3/21/22
to Google Ads API and AdWords API Forum
Hi Google Ads Team,

I was trying to fetch a report using google ads API search stream. But unfortunately API always returns with 10ki records only. As per my understanding after reading the documentation "SearchStream" doesn't need to mention page_size param.

Please help me to resolve this. Below are my code the way I am doing.

GoogleAdsServiceClient googleAdsServiceClient =
client.GetService(Services.V10.GoogleAdsService);

            // Create a query that retrieves campaigns.
            string query = @"SELECT campaign.id, campaign.name, ad_group.id, metrics.cost_micros, group_placement_view.display_name,group_placement_view.target_url, metrics.average_cost, metrics.average_cpc, metrics.average_cpe, metrics.average_cpm, metrics.conversions, metrics.clicks, segments.date FROM group_placement_view WHERE  segments.date BETWEEN '2022-02-01' AND '2022-03-15'";

            // Issues a search request.
            googleAdsServiceClient.SearchStream("XXXXXXX", query,
                delegate (SearchGoogleAdsStreamResponse response)
                {
                    if (response.Results.Count() == 0)
                    {
                        Console.WriteLine("No results found!");
                        Console.ReadLine();
                        return;
                    }

                    CsvFile csvFile = new CsvFile();

                    // Set the header for the CSV file.
                    csvFile.Headers.AddRange(response.FieldMask.Paths);

                    // Iterate over all returned rows and extract the information.
                    foreach (GoogleAdsRow googleAdsRow in response.Results)
                    {
                        csvFile.Records.Add(new string[]
                        {
                            googleAdsRow.Campaign.Id.ToString(),
                            googleAdsRow.Campaign.Name,
                            googleAdsRow.AdGroup.Id.ToString(),
                            googleAdsRow.Metrics.CostMicros.ToString(),
                            googleAdsRow.GroupPlacementView.DisplayName.ToString(),
                            googleAdsRow.GroupPlacementView.TargetUrl.ToString(),
                            googleAdsRow.Metrics.AverageCost.ToString(),
                            googleAdsRow.Metrics.AverageCpc.ToString(),
                            googleAdsRow.Metrics.AverageCpe.ToString(),
                            googleAdsRow.Metrics.AverageCpm.ToString(),
                            googleAdsRow.Metrics.Conversions.ToString(),
                            googleAdsRow.Metrics.Clicks.ToString(),
                            googleAdsRow.Segments.Date
                        });
                    }

                    if (outputFilePath == null)
                    {
                        outputFilePath =
                            Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) +
                            Path.DirectorySeparatorChar +
                            GetType().Name +
                            DateTime.Now.ToString("-yyyyMMMMdd-HHmmss") + ".csv";
                    }
                    else if (!outputFilePath.EndsWith(".csv"))
                    {
                        outputFilePath += ".csv";
                    }

                    // Create the file with the specified path, write all lines, and close it.
                    csvFile.Write(outputFilePath);

                    Console.WriteLine(
                        $"Successfully wrote {response.Results.Count()} entries to {outputFilePath}.");
                    Console.ReadLine();
                }
            );



Google Ads API Forum Advisor

unread,
Mar 21, 2022, 3:35:25 PM3/21/22
to moidee...@gmail.com, adwor...@googlegroups.com
Hi Moideen,

Could you privately send a request and response log of API communication when log level is set to ‘DEBUG' of the report you are trying to make a csv file out of?

The request and response appears similar to the JSON Mappings in our REST documentation with additional information such as  request ID. Our client libraries have loggers with logging instructions, to see these instructions you can click on the client library you use in the sidebar of our client library guide and click on "Logging”.

Regards,

Google Logo
Aryeh
Google Ads API Team
 


ref:_00D1U1174p._5004Q2YpoIs:ref

Moideen Shihab Vaisyar Kandi

unread,
Mar 23, 2022, 2:50:02 AM3/23/22
to Google Ads API and AdWords API Forum
Can I have your private email address, So I can share the DEBUG log with you?

Google Ads API Forum Advisor

unread,
Mar 25, 2022, 1:36:39 PM3/25/22
to moidee...@gmail.com, adwor...@googlegroups.com
Hi Moideen,

It appears you haven't received the email I sent, so here's a copy:

Hi Moideen,

My team came back to me with this:
 

The delegate callback will be called for each page in the stream, each of which has exactly 10K results. Typically your last page has < 10K results, but since 800K is an exact multiple of 10K, your last page also has 10K rows.

 

This code is overwriting each subsequent page. So move the CsvFile initialization before the API call, and writing to file outside the delegate after the method call. That should fix the code.

Regards,

Reply all
Reply to author
Forward
0 new messages