I am creating an Azure function (C# using dotnet core 3.1) that will call 
the Google Ads API. Since this application has no UI I believe that I need 
to use a service account to authenticate.

The code runs and returns an error "authenticationError": "NOT_ADS_USER"

The login that I used to create the service account is a google ads user in 
the ads portal with a role of Admin.

The developer token used has basic access and the manager account is linked 
to the customers account.

The full code and error message is listed below.
*What am I missing?*

GoogleAdsConfig config = new GoogleAdsConfig()
            {
           OAuth2Mode = 
Google.Ads.GoogleAds.Config.OAuth2Flow.SERVICE_ACCOUNT,
           OAuth2SecretsJsonPath = pathtojsonfile,
           OAuth2PrnEmail = 
"someth...@somethingelse.iam.gserviceaccount.com",
           OAuth2Scope = "https://www.googleapis.com/auth/adwords";,
           DeveloperToken = "********"
        };
        
        var responseMessage = "";
        var client = new GoogleAdsClient(config);
        

        // Get the GoogleAdsService.
        GoogleAdsServiceClient googleAdsService = 
client.GetService(Services.V6.GoogleAdsService);

        // Create the query.
        string query =
            @"SELECT
             campaign.id,
             campaign.name,
             ad_group.id,
             ad_group.name,
             ad_group_criterion.criterion_id,
             ad_group_criterion.keyword.text,
             ad_group_criterion.keyword.match_type,
             metrics.impressions,
             metrics.clicks,
             metrics.cost_micros
         FROM keyword_view
         WHERE segments.date DURING LAST_7_DAYS
             AND campaign.advertising_channel_type = 'SEARCH'
             AND ad_group.status = 'ENABLED'
             AND ad_group_criterion.status IN ('ENABLED','PAUSED')
         ORDER BY metrics.impressions DESC
         LIMIT 50";

        try
        {
            // Issue a search request.
            await googleAdsService.SearchStreamAsync(customerId.ToString(), 
query,
                delegate (SearchGoogleAdsStreamResponse resp)
                {
                    // Display the results.
                    foreach (GoogleAdsRow criterionRow in resp.Results)
                    {
                        responseMessage +=
                            "Keyword with text " +
                            
$"'{criterionRow.AdGroupCriterion.Keyword.Text}', match type " +
                            
$"'{criterionRow.AdGroupCriterion.Keyword.MatchType}' and ID " +
                            $"{criterionRow.AdGroupCriterion.CriterionId} 
in ad group " +
                            $"'{criterionRow.AdGroup.Name}' with ID " +
                            $"{criterionRow.AdGroup.Id} in campaign " +
                            $"'{criterionRow.Campaign.Name}' with ID " +
                            $"{criterionRow.Campaign.Id} had " +
                            $"{criterionRow.Metrics.Impressions.ToString()} 
impressions, " +
                            $"{criterionRow.Metrics.Clicks} clicks, and " +
                            $"{criterionRow.Metrics.CostMicros} cost (in 
micros) during the " +
                            "last 7 days.";
                    }
                }
            );
        }
        catch (GoogleAdsException e)
        {
            responseMessage += "Failure:\n";
            responseMessage += $"Message: {e.Message}\n";
            responseMessage += $"Failure: {e.Failure}\n";
            responseMessage += $"Request ID: {e.RequestId}\n";
            throw;
        }

        return responseMessage;

------------------------------------------------------------------
{  
  "StatusCode": 16,  
  "Details": "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.";,  
  "RequestId": "0Yk2OYrUATjwftZ5I0qi2g",  
  "Failure": {  
    "errors": [  
      {  
        "errorCode": {  
          "authenticationError": "NOT_ADS_USER"  
        },  
        "message": "User in the cookie is not a valid Ads user."  
      }  
    ]  
  }  
}  





-- 


-- 


The content of this message is confidential. If you have received it by 
mistake, please inform us by an email reply, delete the message, and do not 
forward the contents of this message to anyone. The integrity and security 
of this email cannot be guaranteed over the Internet. Therefore, the sender 
and company will not be held liable for any damage caused by the message. 
Finally, the opinions disclosed by the sender do not have to reflect those 
of the company, therefore the company refuses to take any liability for the 
damage caused by the content of this email.


If it is not necessary to 
print this email, please help us keep the environment litter-free

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/85eea414-389d-414f-95ba-8fd1a625da9bn%40googlegroups.com.

Reply via email to