title: Facebook Access Token from Website cookie using new OAuth and C#
body: <p>Alright, so I've seen this question asked but yet have found a simple answer that works.</p>
  
  <p>A user comes to my website and has already "authorized" my website/app using the standard facebook login dialog - USING oauth.</p>
  
  <p>Upon returning to my site the user has a cookie on his machine that starts with "fbsr_%" - from what I'm reading this is considered "the code".</p>
  
  <p>What I'd like to do now is grab this cookie server-side, make a call to facebook, from what I found I'm supposed to call: "https://graph.facebook.com/oauth/access_token?client_id={0}&amp;redirect_uri={1}&amp;client_secret={2}&amp;code={3}"</p>
  
  <p>then receive back the accesstoken...</p>
  
  <p>I would like to receive the access token without having to redirect the user on the client. So what I have so far is as follows, and from what I've gathered it is supposed to work, but for me it always gives me a an error "The remote server returned an error: (400) Bad Request."</p>
  
  <pre><code>string url = "https://graph.facebook.com/oauth/access_token?client_id={0}&amp;redirect_uri={1}&amp;client_secret={2}&amp;code={3}";  
  string redirectUri = "http://www.mysite.com/";  
  string code = Request.Cookies["fbsr_" + clientId].Value;
  
  WebRequest request = WebRequest.Create(string.Format(url, clientId, redirectUri, clientSecret, code));    
  WebResponse response = request.GetResponse();
  
  Stream stream = response.GetResponseStream();  
  Encoding encode = System.Text.Encoding.GetEncoding("utf-8");  
  StreamReader streamReader = new StreamReader(stream, encode);  
  string accessToken = streamReader.ReadToEnd().Replace("access_token=", "");  
  streamReader.Close();  
  response.Close();  
  </code></pre>
  
  <p>Any help would be greatly appreciated</p>