RE: General Google Oauth2 confusion ('invalid_grant' when exchanging authorization code)

247 views
Skip to first unread message
Message has been deleted

Google Ads API Forum Advisor

unread,
Jun 23, 2022, 11:47:21 PM6/23/22
to nsk...@gmail.com, adwor...@googlegroups.com
Hi Dmitry,

Thank you for raising this concern to the Google Ads API team.

Moving forward, kindly note that our team supports AdWords API / Google Ads API related concerns. 

Also, upon seeing your email, it appears that you are using the Gmail API. That said, I am afraid that this is already out of our scope and I would suggest reaching out to the Gmail API support team via this link.

Regards,
Google Logo
Carmela
Google Ads API Team
 


ref:_00D1U1174p._5004Q2bzj9l:ref

Ngon Nguyen

unread,
Jul 12, 2022, 2:41:47 AM7/12/22
to nsk...@gmail.com, Google Ads API and AdWords API Forum

Vào 3:04, Th 6, 24 thg 6, 2022 Dmitry M <nsk...@gmail.com> đã viết:
Team,

After Google blocked the 'less secure apps' access to Gmail and such I'm trying to rewrite my client code to use Google's OAuth2 API.

But I'm stuck w/the notorious 'invalid_grant' issue.
Here, pay attention: this is about the very 'second' step - exchanging authorization code to the tokens very first time.

My general approach:

- I'm sending a request to get the authorization code from the browser (simply putting it in the address box):


- I'm receiving an OK response w/the authorization code alright

- I'm sending then an HTTP POST (from the same browser console like)

var params = 'code=<code-here>&client_id=<client-id-here>&client_secret=<client-secret-here>&redirect_uri=http%3A//localhost&grant_type=authorization_code';

var http = new XMLHttpRequest();

http.open('POST', url, true);

http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

http.send(params);

- I'm receiving response like

{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}

Can anyone please advise?

Thanks.

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api...@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 "Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/05d7658b-bb76-4ecf-a517-05497f382814n%40googlegroups.com.

Google Ads API Forum Advisor

unread,
Jul 12, 2022, 4:06:00 AM7/12/22
to ngonng...@gmail.com, nsk...@gmail.com, adwor...@googlegroups.com

Hi,

Thanks for reaching out to the Google Ads API Forum.

Since you mentioned that you trying to access to Gmail with Google's OAuth2, but this forum supports OAuth issue while accessing Google Ads API.

Upon checking the stack trace you’ve provided with us, I can see that you’ve encountered the invalid_grant error. Kindly note that the invalid_grant usually indicates an issue with the refresh token. That said, you’ll need to regenerate credentials and refresh tokens. You may refer here to this guide for the steps on how you can regenerate credentials and refresh tokens.

In addition, you may need to use correct scope for Google Ads API. The present scope for the Google Ads API is: https://www.googleapis.com/auth/adwords.

If the issue still persists while accessing Google Ads API, then you may privately provide the complete request and response logs with the request-id generated in said format for the API error. You may enable logging so you’ll get complete request and response logs along with request-id by navigating to the Client libraries > Your client library (ex Java) > Logging documentation, which you can access from this link

If yo’re not using Google Ads API but Gmail, we highly suggest that you reach out to the Google API console support team via this API Console Help link.

Regards,

Google Logo
Yasar
Google Ads API Team
 


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