I am not able to get new access token using refresh token 
*ERROR : The remote server returned an error: (400) Bad Request.*

public static string PostMethod(string baseAddress, string data)
{
    try
    {
        HttpWebRequest request = HttpWebRequest.Create(baseAddress) as 
HttpWebRequest;
        string result = null;
        request.Method = "POST";
        request.KeepAlive = true;
        request.ContentType = "application/x-www-form-urlencoded;";
        string param = string.Format(data);
        var bs = Encoding.UTF8.GetBytes(param);
        using (Stream reqStream = request.GetRequestStream())
        {
            reqStream.Write(bs, 0, bs.Length);
        }
        using (WebResponse response = request.GetResponse())
        {
            var sr = new StreamReader(response.GetResponseStream());
            result = sr.ReadToEnd();
            sr.Close();
        }
        return result;
    }
    catch (Exception ex)
    {
        throw;
    }
}


private string GetToken(GmailIntegrationModel gmailIntegrationModel, string 
subscribedCompanyId)
{
    _logger.LogDebug("GetToken in.");
    try
    {
        //string Url = "https://www.googleapis.com/oauth2/v4/token?";;
        string Url = "https://accounts.google.com/o/oauth2/token";;
        var credentials = GetGmailCredentials(subscribedCompanyId);
        var data = "client_id=" + credentials.UserName + "&client_secret=" 
+ credentials.ApiKey + "&refresh_token=" + 
gmailIntegrationModel.Refresh_Token + "&grant_type=refresh_token";
        var result = CommonMethod.PostMethod(Url, data);
        var res = 
JsonConvert.DeserializeObject<GmailIntegrationModel>(result);
        return res.Access_token;

    }
    catch (Exception ex)
    {
        _logger.LogError(ex.Message, ex);
        throw;
    }
}

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/5fdc1c4d-d85b-4581-b7de-05b513c7594fn%40googlegroups.com.
  • I ... Hardik Masalawala
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to