title: Get User Access Token of Facebook in C# console application
body: <p>I want to create a C# console application to create a post on my FaceBook account wall.</p>
  
  <p>I tried to search how to get this but all i get is information about get access_token in web application where we can add redirect URL : <a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>.</p>
  
  <p>I am using below code to get an access_token in Console application.
  But i get output from this below code is :</p>
  
  <p>{
      "access_token": "*****|*************",
      "token_type": "bearer"
  }
  Which App_ID|App_Secret..where user Access_token should be of very big length.</p>
  
  <p>Is this possible to post on facebook account wall using console application??</p>
  
  <pre><code>    private const string FacebookApiId = "************";
      private const string FacebookApiSecret = "**************************";
  
      private const string AuthenticationUrlFormat =
           "https://graph.facebook.com/oauth/access_token?client_id={0}&amp;client_secret={1}&amp;grant_type=client_credentials&amp;scope=manage_pages,offline_access,publish_stream";
  
  
      static void Main(string[] args)
      {
  
          string accessToken = GetAccessToken(FacebookApiId, FacebookApiSecret);
  
          PostMessage(accessToken, "My message");
      }
  
      static string GetAccessToken(string apiId, string apiSecret)
      {
          string accessToken = string.Empty;
          string url = string.Format(AuthenticationUrlFormat, apiId, apiSecret, "manage_pages,offline_access,publish_stream");
  
          WebRequest request = WebRequest.Create(url);
  
          WebResponse response = request.GetResponse();
  
          using (Stream responseStream = response.GetResponseStream())
          {
              StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
              String responseString = reader.ReadToEnd();
  
              NameValueCollection query = HttpUtility.ParseQueryString(responseString);
  
              accessToken = query["access_token"];
          }
  
          if (accessToken.Trim().Length == 0)
              throw new Exception("There is no Access Token");
  
          return accessToken;
      }
  </code></pre>