Generating Token

59 views
Skip to first unread message

Saif Quraishi

unread,
Sep 19, 2022, 6:44:38 AM9/19/22
to Google Ads API and AdWords API Forum
Hi Team,
   Below I am attached my format  of code to generate Toke , but I am getting Error , please suggest me ..
--------------------------------------------------------------------------------------------------------------------------------------
The Error I am getting:
{
    "error": "invalid_grant",
    "error_description": "Bad Request"
}
--------------------------------------------------------------------------------------------------------------------------------------
string clientId = _configuration["GoogleAPISettingsAuth:client_id"];
                string clientSecret = _configuration["GoogleAPISettingsAuth:client_secret"];
                string redirectUrl = _configuration["GoogleAPISettingsAuth:redirect_url"];
                http.DefaultRequestHeaders.Clear();
                string url = "https://oauth2.googleapis.com/token";
                url += "?code=" + code + "&client_id=" + clientId + "&client_secret=" + clientSecret;
                url += "&redirect_uri=" + redirectUrl + "&grant_type=authorization_code";
                http.DefaultRequestHeaders.Accept.Add(
                        new MediaTypeWithQualityHeaderValue("application/json"));              
                HttpResponseMessage httpResponse = await http.PostAsJsonAsync(url, new object());
                string strResponse = httpResponse.Content.ReadAsStringAsync().Result;

----------------------------------------------------------------------------------------------------------------------------------------------

Google Ads API Forum Advisor

unread,
Sep 19, 2022, 9:59:40 AM9/19/22
to ansit...@gmail.com, adwor...@googlegroups.com
Hi Saif,

Thank you for reaching out to us.

The "invalid_grant” error usually indicates an issue with the refresh token. That said, you will 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.

If you are still having an issue, please share the complete request and response logs with request ID so we can take a closer look at the issue. You may then send this information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Best regards,
Google Logo
Heidi
Google Ads API Team
 


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