googleads / google-ads-dotnet

This project hosts the .NET client library for the Google Ads API.
https://developers.google.com/google-ads/api
Apache License 2.0
75 stars 94 forks source link

InvalidArgument - PAGE_SIZE_NOT_SUPPORTED even when not setting SearchGoogleAdsRequest.PageSize or default value for pageSize parameter #589

Open b-levitt opened 9 hours ago

b-levitt commented 9 hours ago

V17/V18 throws 'PAGE_SIZE_NOT_SUPPORTED' even when the field/param is set to default

Steps to Reproduce: Linqpad script using 21.1.1 Google.Ads nuget:

`void Main() { GoogleAdsServiceClient _googleAdServiceClient;

var _config = new GoogleAdsConfig(new Dictionary<string, string> {
        { "AuthorizationMethod", "OAuth2" },
        { "DeveloperToken", "xxxx" },
        { "OAuth2ClientId", "xxxx.apps.googleusercontent.com" },
        { "OAuth2ClientSecret", "xxxx" },
        { "OAuth2RefreshToken", "xxxx" },
        { "OAuth2Mode", "APPLICATION" },
        { "LoginCustomerId", "xxxx" }
    });

var _client = new GoogleAdsClient(_config);
_googleAdServiceClient = _client.GetService(Services.V18.GoogleAdsService);

var search = new SearchGoogleAdsRequest();
search.Query =
    @$"SELECT
    campaign.id,
    campaign.name,
    campaign.status,
    metrics.average_cpc,
    metrics.average_cpm,
    metrics.average_cost,
    metrics.clicks,
    metrics.impressions,
    segments.date,
    ad_group.id,
    ad_group.name
    FROM ad_group WHERE campaign.status != 'REMOVED' AND segments.date >= '2024-11-01' AND segments.date <= '2024-12-3'";
search.CustomerId = "9999999";

Page<GoogleAdsRow> results = null;

var request = _googleAdServiceClient.Search(search);
//****************     exception thrown here  vvvvvvvvvvvvvvvvv
results = request.ReadPage(10000);

}

`

Expected behavior: PageSize not set in output with at least ONE "magic" page size, allowing for use of the latest V17/V18 api

Client library version and API version: Client library version:21.1.1 Google Ads API version:17 and 18 .NET version: .net 8

Request/Response Logs: Nothing is logged when setting ReadPage(0). When pageSize into ReadPage is given, you can see it in the request:

GoogleAds.DetailedRequestLogs Information: 1 : [2024-12-04 17:54:08Z] - ---------------BEGIN API CALL---------------

Request

Method Name: /google.ads.googleads.v17.services.GoogleAdsService/Search Host: Headers: { "x-goog-api-client": "gl-dotnet/3.1.0 gapic/21.1.1 gax/4.8.0 grpc/2.60.0 gccl/4.0.3 pb/3.25.0", "developer-token": "REDACTED", "login-customer-id": "1234665825", "x-goog-request-params": "customer_id=2305300261" }

{ "customerId": "2305300261", "query": "SELECT\r\n\t\tcampaign.id,\r\n\t\tcampaign.name,\r\n\t\tcampaign.status,\r\n\t\tmetrics.average_cpc,\r\n\t\tmetrics.average_cpm,\r\n\t\tmetrics.average_cost,\r\n\t\tmetrics.clicks,\r\n\t\tmetrics.impressions,\r\n\t\tsegments.date,\r\n\t\tad_group.id,\r\n\t\tad_group.name\r\n\t\tFROM ad_group WHERE campaign.status != 'REMOVED' AND segments.date \u003e= '2024-11-01' AND segments.date \u003c= '2024-12-03'", "pageSize": 10 }

Response

Headers: { "request-id": "HdZbTjBpWqp8W46HU5NYSQ", "date": "Wed, 04 Dec 2024 17:54:08 GMT", "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000", "google.ads.googleads.v17.errors.googleadsfailure-bin": "CmkKAggoEmNTZXR0aW5nIHRoZSBwYWdlIHNpemUgaXMgbm90IHN1cHBvcnRlZC4gU2VhcmNoIFJlc3BvbnNlcyB3aWxsIGhhdmUgZml4ZWQgcGFnZSBzaXplIG9mICcxMDAwMCcgcm93cy4SFkhkWmJUakJwV3FwOFc0NkhVNU5ZU1E=", "grpc-status-details-bin": "CAMSJVJlcXVlc3QgY29udGFpbnMgYW4gaW52YWxpZCBhcmd1bWVudC4azAEKRHR5cGUuZ29vZ2xlYXBpcy5jb20vZ29vZ2xlLmFkcy5nb29nbGVhZHMudjE3LmVycm9ycy5Hb29nbGVBZHNGYWlsdXJlEoMBCmkKAggoEmNTZXR0aW5nIHRoZSBwYWdlIHNpemUgaXMgbm90IHN1cHBvcnRlZC4gU2VhcmNoIFJlc3BvbnNlcyB3aWxsIGhhdmUgZml4ZWQgcGFnZSBzaXplIG9mICcxMDAwMCcgcm93cy4SFkhkWmJUakJwV3FwOFc0NkhVNU5ZU1E=" }

Fault: { "StatusCode": 3, "Details": "Request contains an invalid argument.", "RequestId": "HdZbTjBpWqp8W46HU5NYSQ", "Failure": { "errors": [ { "errorCode": { "requestError": "PAGE_SIZE_NOT_SUPPORTED" }, "message": "Setting the page size is not supported. Search Responses will have fixed page size of '10000' rows." } ], "requestId": "HdZbTjBpWqp8W46HU5NYSQ" } } ----------------END API CALL----------------

Anything else we should know about your project / environment

I don't care what the page size is and I'm aware that as of V17 it is a fixed 10k:

https://ads-developers.googleblog.com/2024/06/announcing-v17-of-google-ads-api.html

However, there doesn't seem to be a way to take advantage of that new fixed size with the current .net implimentation since there is only one ReadPage(int pageSize) method, suggesting that you must set a page size. (A page size of 0 yields no rows).

Raibaz commented 7 hours ago

You don't need to use the ReadPage(int pageSize) method, you can iterate or enumerate on the PagedEnumerable<SearchGoogleAdsResponse, GoogleAdsRow> object returned by Search.

Take a look at how this is handled, for instance, in the GetResponsiveSearchAds example: https://github.com/googleads/google-ads-dotnet/blob/main/Google.Ads.GoogleAds/examples/BasicOperations/GetResponsiveSearchAds.cs#L119

Hope this helps.

b-levitt commented 7 hours ago

That's a good tip, thank you. I actually started converting to the preferred "SearchStream" method so either way I have a couple of workarounds.

That said if ReadPage does not work, shouldn't it be removed or marked as obsolete to be inline with the API documentation?

Raibaz commented 6 hours ago

It's a good point, but the PagedEnumerable class and its ReadPage method are actually part of the generic gRPC library, they are not strictly Ads API-specific: https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.GrpcPagedEnumerable-3#Google_Api_Gax_Grpc_GrpcPagedEnumerable_3_ReadPage_System_Int32_

This being said, maybe we can just override it in the Ads API to ensure it's at least marked as obsolete.