I am using .net client library to access google ads API using C# .NET.

I have configured 'Installed App' account in following order:

  1. Configured Manager Account for Developer Token.
  2. Created oAuth credentials using Manager Account and developer console
  3. Created test manager account (test Account isn't linked to Ads account).
  4. Enabled Ads API from Ads Console.
  5. Placed configuration in App.Config

App.Config configuration:

    <add key = 'OAuth2Mode' value = 'APPLICATION' />     <add key = 'OAuth2ClientId' value = 'OAUTH-CLIENT-ID' />     <add key = 'OAuth2ClientSecret' value = 'SECRET' />     <add key = 'OAuth2RefreshToken' value = 'REFRESH-TOKEN' />     <add key="DeveloperToken" value="DEV-TOKEN" /> 

I got refresh token from adwords client-library OAuthTokenGenerator.exe using Test account.

Here is my code to access Ads API:

 public static void GetCampaigns(GoogleAdsClient client, long customerId)  {       client.Config.LinkedCustomerId = customerId.ToString();       GoogleAdsServiceClient googleAdsService = client.GetService(Services.V9.GoogleAdsService);       string query = @"SELECT                             campaign.id,                             campaign.name,                             campaign.network_settings.target_content_network                         FROM campaign                         ORDER BY campaign.id";             try             {                 // Issue a search request.                 googleAdsService.SearchStream(customerId.ToString(), query,                     delegate (SearchGoogleAdsStreamResponse resp)                     {                         foreach (GoogleAdsRow googleAdsRow in resp.Results)                         {                             Console.WriteLine("Campaign with ID {0} and name '{1}' was found.",                                 googleAdsRow.Campaign.Id, googleAdsRow.Campaign.Name);                         }                     }                 );             }             catch (GoogleAdsException e)             {                 Console.WriteLine("Failure:");                 Console.WriteLine($"Message: {e.Message}");                 Console.WriteLine($"Failure: {e.Failure}");                 Console.WriteLine($"Request ID: {e.RequestId}");                 throw;             }         } 

However i am receiving this exception on calling API:

 Status(StatusCode="Unauthenticated", Detail="Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1643028386.159000000","description":"Error received from peer ipv4:142.250.181.106:443","file":"..\..\..\src\core\lib\surface\call.cc","file_line":1070,"grpc_message":"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}") 

can anyone guide me what am i missing in this configuration?

Tag:google-ads-api, c#, .net

Add a new comment.