使用服务帐户+域范围内的委托向Google Ads API进行身份验证时出现invalid_client错误

时间:2019-09-10 16:40:23

标签: c# service-accounts google-ads-api

我正在尝试使用以下针对c#https://github.com/googleads/googleads-dotnet-lib的API客户端向Google Ads进行身份验证。我正在尝试使用服务帐户+ gsuite域范围内的委派进行身份验证。我已经执行了this文档中的所有步骤,但是收到了Google的invalid_client错误。下面是我正在运行的代码。

GoogleAdsClient client = new GoogleAdsClient();
client.Config.OAuth2Mode = OAuth2Flow.SERVICE_ACCOUNT;
client.Config.OAuth2PrnEmail = "useremail@gsuite.com";
client.Config.OAuth2SecretsJsonPath = HostingEnvironment.MapPath("~/service-account-keys-downloaded-from-gcp.json");
var svc = client.GetService(Services.V2.CustomerService);
var accounts = svc.ListAccessibleCustomers();

该代码应代表gsuite组织中的用户进行身份验证,并列出该用户有权访问的所有帐户。当我运行上面的代码时,出现以下错误。

Status(StatusCode=Unavailable, Detail="Getting metadata from plugin
failed with error: Exception occurred in metadata credentials plugin.
Google.Apis.Auth.OAuth2.Responses.TokenResponseException:
Error:"invalid_client", Description:"The OAuth client was not found.", Uri:""

看来,无论我尝试使用哪种电子邮件进行身份验证,我仍然会收到相同的错误,这使我认为我如何进行身份验证存在根本问题。

所有必要字段似乎都正确映射到GoogleAdsClient Config中,但客户端机密除外。我无法将客户端密码传递到请求中,因为服务帐户客户端(在GCP中的服务帐户上启用域范围委派时自动创建)未附带客户端密码。我提到的文档似乎并未指定在使用Google服务帐户进行身份验证时如何获取客户机密,但这似乎是必要的。

0 个答案:

没有答案