Failed to refresh access token - invalid_grant error

147 views
Skip to first unread message

Gal Talmor

unread,
Sep 29, 2020, 8:12:37 AM9/29/20
to AdWords API and Google Ads API Forum
Hello,
I try to call TargetingIdeaService using the SDK (Google.AdWords NuGet, version 24.1.0).
First I received a "CUSTOMER_NOT_ACTIVE" error. I created new credentials and generated a refresh token in console.developers.google.com, and the error changed to "Failed to refresh access token". I receive this error in the official tests project I downloaded, so I guess that it's something in the credentials and not in the code.
Could you please help? Why does the token suppose to be refreshed if I just created it?

The request code:
             string accountId = "ACCOUNT_ID"; 

            AdWordsUser user = GoogleHelper.GetUserForTargetingIdeaService(accountId);

            using (var srv = user.GetService(AdWordsService.v201809.TargetingIdeaService) as TargetingIdeaService)
            {
                var pl = new List<SearchParameter>
                {
                   // ...
                };
                var selector = new TargetingIdeaSelector
                {
                    requestType = RequestType.STATS,
                    ideaType = IdeaType.KEYWORD,
                    paging = Paging.Default,
                    searchParameters = pl.ToArray(),
                    requestedAttributeTypes = new AttributeType[]
                    {
                        AttributeType.SEARCH_VOLUME, AttributeType.KEYWORD_TEXT,
                        AttributeType.AVERAGE_CPC, AttributeType.TARGETED_MONTHLY_SEARCHES, AttributeType.COMPETITION
                    }
                };
               
   TargetingIdeaPage page = await srv.getAsync(selector);
   // ...
          }

The response:
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_grant", Description:"Bad Request", Uri:""   at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.<ExecuteAsync>d__0.MoveNext()
...

Thanks,
Gal

Google Ads API Forum Advisor Prod

unread,
Sep 29, 2020, 1:30:43 PM9/29/20
to gal.t...@market.com, adwor...@googlegroups.com
Hi Gal,

Please reply privately to author your SOAP request and response so that I can further investigate. Please also let me know the user email that you were using with your credentials.

Thanks,
Anthony
Google Ads API Team

Google Logo
Anthony
Google Ads API Team
 


ref:_00D1U1174p._5004Q25XhJB:ref

Gal Talmor

unread,
Sep 30, 2020, 8:53:43 AM9/30/20
to AdWords API and Google Ads API Forum
Hi,
I am sorry, I have no permission to reply to the author only. The option is disabled and I see this tooltip: "You do not have permission to reply to author in this group".

Anyway, I cannot see an actual API call, this exception is thrown from the Google.AdWords NuGet before actually make any API call.
I think that I miss "access token" parameter, I have "refresh token" only (which is different).  Is it necessary?
2020-09-30 15_46_48-AdWords (Debugging) - Microsoft Visual Studio.png

Thanks,
Gal

Google Ads API Forum Advisor Prod

unread,
Sep 30, 2020, 11:41:49 AM9/30/20
to gal.t...@market.com, adwor...@googlegroups.com
Hi Gal,

You will need to obtain an access token. You can find more details on how to generate one here.

Regards,

Gal Talmor

unread,
Oct 5, 2020, 4:39:22 AM10/5/20
to AdWords API and Google Ads API Forum
Hi,
I am sorry but the link is not working.
Could you please check it again?

Thanks,
Gal

Google Ads API Forum Advisor Prod

unread,
Oct 5, 2020, 10:11:55 AM10/5/20
to gal.t...@market.com, adwor...@googlegroups.com
Hi Gal,

Please try to open the link on a private window. If you still have issues, please send me a screenshot of the webpage.

Gal Talmor

unread,
Nov 25, 2020, 8:09:54 AM11/25/20
to AdWords API and Google Ads API Forum
Hi,
I am sorry for the delay.
It's working now! :)
I had to fill both OAuth2RefreshToken and OAuth2AccessToken in the AdWordsAppConfig.

To create a "refresh token":
https://accounts.google.com/o/oauth2/auth?access_type=offline&state&response_type=code&client_id=MY_CLIENT_ID&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords 
 
To create an "access token":
https://accounts.google.com/o/oauth2/auth?client_id= MY_CLIENT_ID&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&redirect_uri=urn:ietf:wg:oauth:2.0:oob&access_type=offline&prompt=consent

Thanks,
Gal

Google Ads API Forum Advisor Prod

unread,
Nov 26, 2020, 1:20:15 AM11/26/20
to gal.t...@market.com, adwor...@googlegroups.com
Hi Gal,

I am happy to know that your API is working now. Feel free to post your further concerns on this forum and our team would be happy to provide support.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q25XhJB:ref
Reply all
Reply to author
Forward
0 new messages