C# Migrate from AdWords API v201708 to v201809 - The OAuth client was not found

37 views
Skip to first unread message

bberlin

unread,
Jan 3, 2019, 4:33:01 PM1/3/19
to AdWords API and Google Ads API Forum

Hello, we are migrating from AdWords API v201708  to  v201809.  

We do uninstall NuGet v201708   and installed v201809, and replaced "using" -s to v201809.

The build passed without any errors or warnings.  However when we run the code we got an the run-time shows an error of 

"AdsOAuthException: Failed to refresh access token"   ( I put the full  Exception stack dump below).

Why do we have it , if the same code at the same time now , linked with v201708   works out without any errors.

I also put the code snippet below the Exception stack dump in order to show the idea if the call, 

in spite it should not be much matter, since the same works out  for v201708   .

Regards,

Boris


== Exception stack  ===============
Google.Api.Ads.Common.Lib.AdsOAuthException: Failed to refresh access token. ---> System.AggregateException: One or more errors occurred. ---> Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error:"invalid_client", Description:"The OAuth client was not found.", Uri:""
   at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.<FetchTokenAsync>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.<FetchTokenAsync>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.Flows.AuthorizationCodeFlow.<RefreshTokenAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.UserCredential.<RefreshTokenAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.<RefreshTokenAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.<GetAccessTokenForRequestAsync>d__10.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Google.Api.Ads.Common.OAuth.AdsOAuthProviderImpl.GetAccessTokenForAuthorizationCodeFlow()
   at Google.Api.Ads.Common.OAuth.AdsOAuthProviderImpl.RefreshAccessTokenInOfflineMode()
   --- End of inner exception stack trace ---

Server stack trace:
   at Google.Api.Ads.Common.OAuth.AdsOAuthProviderImpl.RefreshAccessTokenInOfflineMode()
   at Google.Api.Ads.Common.OAuth.AdsOAuthProviderImpl.RefreshAccessToken()
   at Google.Api.Ads.Common.OAuth.AdsOAuthProviderImpl.GetAuthHeader()
   at Google.Api.Ads.Common.OAuth.OAuthClientMessageInspector.BeforeSendRequest(Message& request, IClientChannel channel)
   at System.ServiceModel.Dispatcher.ImmutableClientRuntime.BeforeSendRequest(ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.PrepareCall(ProxyOperationRuntime operation, Boolean oneway, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Google.Api.Ads.AdWords.v201809.ManagedCustomerServiceInterface.get(Selector serviceSelector)
   at Google.Api.Ads.AdWords.v201809.ManagedCustomerService.get(Selector serviceSelector)
==  ======
===  Code snippet -- 
using Google.Api.Ads.AdWords.Lib;
using Google.Api.Ads.AdWords.Util.Reports;
using Google.Api.Ads.AdWords.v201809;
using Google.Api.Ads.Common.Lib;
using Google.Api.Ads.Common.Util.Reports;
........
........
// Get the ManagedCustomerService.
            ManagedCustomerService managedCustomerService = (ManagedCustomerService)m_st_adUser.GetService(
                AdWordsService.v201809.ManagedCustomerService);

            // Create selector.
            Selector selector = new Selector();
            selector.fields = new String[] {
          ManagedCustomer.Fields.CustomerId, ManagedCustomer.Fields.Name
      };
            selector.paging = Paging.Default;

            // Map from customerId to customer node.
            Dictionary<long, ManagedCustomerTreeNode> customerIdToCustomerNode =
                new Dictionary<long, ManagedCustomerTreeNode>();

            // Temporary cache to save links.
            List<ManagedCustomerLink> allLinks = new List<ManagedCustomerLink>();

            ManagedCustomerPage page = null;
            try
            {
                do
                {
                    page = managedCustomerService.get(selector);
.......




Dannison Yao (AdWords API Team)

unread,
Jan 4, 2019, 12:35:40 AM1/4/19
to AdWords API and Google Ads API Forum
Hi Boris,

The error "Failed to refresh access token" means that your refreshToken is probably expired. There might be an issue with your OAuth2 Credentials. I would recommend to regenerate a new set of credentials by following this guide and update your ads.properties with the newly created credentials.

After this, you could retry making your service calls. If it still does not work, kindly provide the error logs so I could investigate this further.

Regards,
Dannison
AdWords API Team
Reply all
Reply to author
Forward
0 new messages