Unable to access customer data

133 views
Skip to first unread message

Dexter

unread,
Mar 7, 2024, 3:27:11 AM3/7/24
to Google Ads API and AdWords API Forum
Hi,

I've enabled the Ads API in the cloud console, created a OAuth Consent Screen,  created credentials for my Web application and saved the Google Ads API OAuth ClientId and Secret for my Projekt. 

When a user is logging in with his Google account into my Application, the application is asking for access to the users Ads data and I'm storing the users refresh token.

Now I'm trying to list accessible customers from this code example, using my ClientId, Client Secret + the User RefreshToken.

 private GoogleAdsConfig googleAdsConfig
 {
     get
     {
         return new GoogleAdsConfig()
         {
             DeveloperToken = "",
             OAuth2Mode = OAuth2Flow.APPLICATION,
             OAuth2ClientId = Configuration["GoogleAdsAPIOAuthClientId"],
             OAuth2ClientSecret = Configuration["GoogleAdsAPIOAuthClientSecret"],
             OAuth2RefreshToken = UserRefreshToken,
             LoginCustomerId = "",
         };
     }
 }
 public GoogleAdsClient getClient()
 {
     return new GoogleAdsClient(googleAdsConfig);
 }

 public List<string> GetGoogleAdsLinkedAccounts()
 {
     GoogleAdsClient client = getClient();
     // Get the CustomerService.
     CustomerServiceClient customerService = client.GetService(Services.V15.CustomerService);
     var customerList = new List<string>();

     // Retrieve the list of customer resources.
     string[] customerResourceNames = customerService.ListAccessibleCustomers();

     // Display the result.
     foreach (string customerResourceName in customerResourceNames)
     {
         customerList.Add(customerResourceName);
     }

     return customerList;
 }

When running this I'm receiving below error, could you advise what I'm doing wrong?

'One or more errors occurred. (Status(StatusCode="Internal", Detail="Error starting gRPC call. TokenResponseException: Error:"unauthorized_client", Description:"Unauthorized", Uri:""", DebugException="Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error:"unauthorized_client", Description:"Unauthorized", Uri:""

Google Ads API Forum Advisor

unread,
Mar 7, 2024, 6:46:05 AM3/7/24
to adclick...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads API support team.

After reviewing your concern, I understand you are getting the unauthorized client error when listing the accessible customers via the Google Ads API. Kindly note that this error usually occurs when there's an issue with your OAuth credentials. Please make sure you have generated them with an email address that has access to your account.

I would recommend checking out this guide to see how Google Ads API calls can be authorized through OAuth2. If possible, re-generate your OAuth credentials as explained in the suggested documentation.

If you are still receiving that error, please share the email address you used to generate the credentials along with complete API logs (request and response with request-id and request header) generated at your end.

Kindly note that you have to enable logging if you are using a client library. You can refer to the guides Java, .Net, PHP, Python, Ruby or Perl to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02rzkmG:ref"

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages