title: Get access token from google oauth from code
body: <p>i used following code to get the access token from code as below</p>
  
  <pre><code>String code = HttpContext.Current.Request["code"];
                      string redirecturl = HttpContext.Current.Request["url"];                                  
  
                      string Url = "https://accounts.google.com/o/oauth2/token";
                      string grant_type = "authorization_code";
                      string redirect_uri_encode = UrlEncodeForGoogle(url);
                      string data = "code={0}&amp;client_id={1}&amp;client_secret={2}&amp;redirect_uri={3}&amp;grant_type={4}&amp;access_type={5}";
  
                      HttpWebRequest request = HttpWebRequest.Create(Url) as HttpWebRequest;
                      string result = null;
                      request.Method = "POST";
                      request.KeepAlive = true;
                      request.ContentType = "application/x-www-form-urlencoded";
                      string param = string.Format(data, code,configurationInfo.oauthclientid , configurationInfo.oauthclientsecretid, redirect_uri_encode, grant_type, "offline");
  
                      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();
  
                      }
  </code></pre>
  
  <p>i am getting response as</p>
  
  <pre><code> The remote server returned an error: (400) Bad Request.
  </code></pre>
  
  <p>i do not know where i went wrong</p>
  
  <p>waiting for your valuable comments</p>