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 97 forks source link

[Urgent] FinalUrls is READONLY #337

Closed ullfindsmit closed 2 years ago

ullfindsmit commented 2 years ago

Describe the bug: FinalURLs is now readonly so I removed the line and now I get an error when trying to create a new Ad.

In the latest library the FinalUrls property is READONLY Assembly Google.Ads.GoogleAds, Version=10.2.0.0, Culture=neutral, PublicKeyToken=52807268f2b614dc

However, in the earlier version it was NOT readonly. Assembly Google.Ads.GoogleAds, Version=10.1.0.0, Culture=neutral, PublicKeyToken=52807268f2b614dc

What is the new way to set the FinalURLs value?

Steps to Reproduce:


                    // Create the ad group ad object.
                    AdGroupAd adGroupAd = new AdGroupAd
                    {
                        AdGroup = oAdGroup,
                        // Optional: Set the status.
                        Status = AdGroupAdStatus.Paused,
                        Ad = new Ad
                        {
                            **FinalUrls = { oAdGroupAd.FinalUrls },**
                            ExpandedTextAd = new ExpandedTextAdInfo
                            {
                                Description = CSVParameterObj.Description,
                                Description2 = CSVParameterObj.Description2,
                                HeadlinePart1 = CSVParameterObj.HeadlinePart1,
                                HeadlinePart2 = CSVParameterObj.HeadlinePart2,
                                HeadlinePart3 = CSVParameterObj.HeadlinePart3,
                                Path1 = CSVParameterObj.Path1,
                                Path2 = CSVParameterObj.Path2
                            }
                        }
                    };

Expected behavior: Backward compatibility or documentation on how to fix.

Client library version and API version: Assembly Google.Ads.GoogleAds, Version=10.2.0.0, Culture=neutral, PublicKeyToken=52807268f2b614dc .NET version: Latest Operating system (Linux, Windows, ...) and version (if the bug is platform-specific): Windows 10

Request/Response Logs: { "StatusCode": 3, "Details": "Request contains an invalid argument.", "RequestId": "--removed--", "Failure": { "errors": [ { "errorCode": { "collectionSizeError": "TOO_FEW" }, "message": "Too few.", "location": { "fieldPathElements": [ { "fieldName": "operations", "index": 0 }, { "fieldName": "create" }, { "fieldName": "ad" }, { "fieldName": "final_urls" } ] } } ], "requestId": "--removed--" } }

Anything else we should know about your project / environment

Not at the moment.

jradcliff commented 2 years ago

Hi,

Thanks for opening the issue here. The error you received looks to be due to there being zero final URLs on the ad sent in the request. Does the ad you're copying from (oAdGroupAd) have a non-empty FinalUrls collection?

Thanks

ullfindsmit commented 2 years ago

Yes, the property FinalUrls collection is blank. The reason it is blank is because the property FinalURLs used to be read/write in 10.1 and is readonly in 10.2 There is no documentation as to HOW to set the value in 10.2.

rivdiv commented 2 years ago

I am hitting this issue as well with setting the FinalURls property on the AdGroupCriterion object. It is read only in both versions 9 and 10.2 which I just upgraded to. https://groups.google.com/g/adwords-api/c/gPS2ibFplVY

vipulpatel007 commented 2 years ago

ullfindsmit is right. In Version 10.1 its allow to set value of finalURLs Please check this Ad Expandend TextAPI

AnashOommen commented 2 years ago

There seems to be multiple issues being discussed on this thread, so let me go over them one by one.

  1. In C#, repeated fields are treated as readonly lists. So this code should work:
private void TryArrayInitialize()
{
  Ad oAdGroupAd = new Ad();
  string oAdGroup = "";
  AdGroupAd adGroupAd = new AdGroupAd
  {
    AdGroup = oAdGroup,
    // Optional: Set the status.
    Status = AdGroupAdStatus.Paused,
    Ad = new Ad
    {
      FinalUrls = { oAdGroupAd.FinalUrls },
      ExpandedTextAd = new ExpandedTextAdInfo
      {
      }
    }
  };
}

The relevant C# feature is discussed here: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/object-and-collection-initializers#object-initializers-with-collection-read-only-property-initialization

  1. The question is why this code stopped working between 10.1 and 10.2. I don't have a good answer to that, because the code hasn't changed between 10.1 and 10.2. So I can't replicate this issue, even though I also don't doubt this might be affecting some users because @friedenberg also ran into this issue once. For reference, here are the files.

https://github.com/googleads/google-ads-dotnet/blob/86eefe5a710abde9e0008325569a348ac5f90402/src/V8/Types/Ad.g.cs#L301-L303

https://github.com/googleads/google-ads-dotnet/blob/127ae517dd612e8d9978838ca04cfe431e40a863/src/V8/Types/Ad.g.cs#L290-L293

Can someone provide a minimal project that helps replicate this issue?

I am using

Microsoft Visual Studio Community 2019
Version 16.11.6
VisualStudio.16.Release/16.11.6+31829.152
Microsoft .NET Framework
Version 4.8.04084

And for command line:

SDK Version: 5.0.404

And OS version:

Windows 10, Microsoft Windows Version 20H2 (OS Build 19042.1415)

The following projects compile fine locally.

Compilation Issues.zip

ullfindsmit commented 2 years ago

@AnashOommen thank you for staying on this issue. The issue is that the FinalURLs property is ReadOnly in 10.2.0.0 and I am not able to set its value as you suggested

FinalUrls = { oAdGroupAd.FinalUrls }

ullfindsmit commented 2 years ago

[image: image.png]

AnashOommen commented 2 years ago

@ullfindsmit can you please attach a minimal project that illustrates the issue? Or otherwise, confirm if you can compile the attached Compilation Issues.zip?

ullfindsmit commented 2 years ago

I was finally able to get it to work. The solution was to not use the inline declaration but instead to create a new Ad object Then instead of assigning the final urls, simply using oAd.FinalURLs.Add("string")

Message ID: @.***>