Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using #592

Open
sommmen opened this issue Dec 20, 2024 · 2 comments
Open

Error when using #592

sommmen opened this issue Dec 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@sommmen
Copy link

sommmen commented Dec 20, 2024

Describe the bug:

A bit of a continuation of #585. I added <PackageReference Include="Google.Ads.GoogleAds.Extensions" Version="2.0.3" /> and decided to use the new extension to configure my google ads client. This fails with the following error:

System.ArgumentException
  HResult=0x80070057
  Message=Parameter was empty (Parameter 'pkcs8PrivateKey')
  Source=Google.Apis.Core
  StackTrace:
   at Google.Apis.Util.Utilities.ThrowIfNullOrEmpty(String str, String paramName)
   at Google.Apis.Auth.OAuth2.Pkcs8.DecodeRsaParameters(String pkcs8PrivateKey)
   at Google.Apis.Auth.OAuth2.ServiceAccountCredential.Initializer.FromPrivateKey(String privateKey)
   at Google.Ads.Gax.Config.AdsConfig.CreateCredentials()
   at Google.Ads.Gax.Config.AdsConfig.get_Credentials()
   at Google.Ads.Gax.Lib.AdsChannel.CreateChannel(String url)
   at Google.Ads.Gax.Lib.AdsChannel..ctor(AdsConfig config, String url)
   at Google.Ads.Gax.Lib.CachedChannelFactory.GetChannel(AdsConfig config, String serverUrl)
   at Google.Ads.GoogleAds.Lib.GoogleAdsServiceClientFactory.CreateChannel(GoogleAdsConfig config)
   at Google.Ads.GoogleAds.Lib.GoogleAdsServiceClientFactory.GetService[TService,TServiceSetting](ServiceTemplate`3 serviceTemplate, GoogleAdsConfig config)
   at Google.Ads.GoogleAds.Lib.GoogleAdsClient.GetService[TService,TServiceSetting](ServiceTemplate`3 serviceTemplate)
   at [REDACTED]

Steps to Reproduce:
Please provide a code snippet or steps to consistently reproduce the experienced behavior.
[DO NOT INCLUDE ANY PERSONAL OR SENSITIVE DATA IN YOUR SUBMITTED CODE]

It seems not all configurations are set on the Google ads object.

appsettings.json

"GoogleAdsApi": {
  "OAuth2PrnEmail": "[REDACTED]",
  "OAuth2SecretsJsonPath": "${Secrets:Google:OauthPath}",
  "OAuth2Mode": "SERVICE_ACCOUNT",
  "DeveloperToken": "[REDACTED]"
},
...

At runtime the path is expanded to a real path using https://github.com/StackExchange/StackExchange.Utils?tab=readme-ov-file#stackexchangeutilsconfiguration. This works as it should.

It seems the OAuth2SecretsJsonPath is not properly passed from the GoogleAdsApiOptions to the GoogleAdsConfig as the other properties are. This is the same for more properties, like OAuth2PrnEmail.

Expected behavior:

Client library version and API version:
Client library version: latest
Google Ads API version: latest
.NET version: latest
Operating system (Linux, Windowlatests, ...) and version (if the bug is platform-specific):

Request/Response Logs:

Anything else we should know about your project / environment

@sommmen sommmen added the bug Something isn't working label Dec 20, 2024
@sommmen
Copy link
Author

sommmen commented Dec 20, 2024

i've worked around this like so;

// TODO workaround see: https://github.com/googleads/google-ads-dotnet/issues/592

//services.AddGoogleAdsClient(_configuration);

services.AddSingleton<IGoogleAdsConfig, GoogleAdsConfig>(_ => new GoogleAdsConfig(_configuration
    .GetSection("GoogleAdsApi")
    .GetChildren()
    .ToDictionary(x => x.Key, x => x.Value)));
services.AddTransient<IGoogleAdsClient, GoogleAdsClient>();

which works.

@Raibaz
Copy link
Contributor

Raibaz commented Dec 20, 2024

Good catch! I think a more long-term fix would be to add setting the OAuth2PrnEmail and OAuth2SecretsJsonPath properties here, though.

I'll get to it as soon as the code freeze season is over, but glad you found a workaround in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants