Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:11:36+00:00 2026-06-02T02:11:36+00:00

I’m developing a desktop application in C#. After visiting https://www.facebook.com/dialog/oauth?client_id=123 the user logs in

  • 0

I’m developing a desktop application in C#.

After visiting https://www.facebook.com/dialog/oauth?client_id=123 the user logs in and the user access token is attached to the redirect uri. Its no problem, when the loginpage is displayed in a webbrowser control in my form, so i can extract the token from the url.

But this is not the way i want to get the token. My question is, is there a way to obtain the freshly created token via an Graph API call?

Because i want to display the login page in the user’s standard browser and not in this embedded webbrowser. All my efforts to get the user access token have been resulted in getting the app access token, which is useless in this case.

Any hints are appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:11:38+00:00Added an answer on June 2, 2026 at 2:11 am

    // This is very raw, And Note it is a MVC3 solution, but it is in C# and I hope it helps.
    // It is basically a C# version of the PHP example on FB for ‘Server Side Flow’
    // I have been at it for a while and had to go through some pain
    // Please note the bug I read about that states the redirect_uri must be the same for both //requests
    // Also read that someone had an issue if the redirect_uri did not end in ‘/’
    // Post back if you hae any ?s as I am just starting this project and am going to try and //incorporate the C# FaceBook SDK

    public class AccountController : Controller
        {
            // LoginWithFaceBook
            // First Contact with FB - oauth?client_id ... redirect_uri = /Account/FacebookLinker 
            // according to a bug files on FB redirect_uri MUST BE SAME FOR both trips ( to get the 'code' then exchange the code for 'access_token'
            public ActionResult ConnectFaceBookAccount()
            {
                string APP_ID = HttpContext.Application["FacebookAppId"].ToString();
                string redirect_uri = HttpContext.Application["FacebookOAuthRedirect"].ToString();
                string state = HttpContext.Application["state_guid"].ToString();
                // in this View I simply link to this URL
                ViewBag.FaceBookOAuthUrl = "https://www.facebook.com/dialog/oauth?client_id=" + APP_ID + "&redirect_uri="+redirect_uri+"&state=" + state+"&display=popup";
    
    
                return View();
            }
    
            // Account/FacebookLinker
            //  redirect_uri for both getting 'code' and exchanging for 'access_token'
            public ActionResult FacebookLinker()
            {
                if (!Request.IsAuthenticated)
                {
                    Response.Redirect("/Account/LogOn");
                }
                // Per FB DOC, Make sure 'state' var returned is same one you sent to reduce chance of Cross Site Forgery
                if (Request.QueryString["state"].ToString() == HttpContext.Application["state_guid"].ToString())
                {
                    try
                    {
    
                        string FBcode = Request.QueryString["code"].ToString();
                        string APP_ID = HttpContext.Application["FacebookAppId"].ToString();
                        string APP_SECRET = HttpContext.Application["FacebookAppSecret"].ToString();
                        string redirect_uri = HttpContext.Application["FacebookOAuthRedirect"].ToString();
    
    
                      string FBAccessUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + APP_ID + "&redirect_uri=" + redirect_uri + "&client_secret=" + APP_SECRET + "&code=" + FBcode;
    
    
                    string accessToken = null;
                    // Send the request to exchange the code for access_token
                    var accessTokenRequest = System.Net.HttpWebRequest.Create(FBAccessUrl);
                    HttpWebResponse response = (HttpWebResponse) accessTokenRequest.GetResponse();
    
                     // handle response from FB 
                     // this will not be a url with params like the first request to get the 'code'
                    Encoding rEncoding = Encoding.GetEncoding(response.CharacterSet);
    
                    using(StreamReader sr = new StreamReader(response.GetResponseStream(),rEncoding))
                    {
                        // parse the response to get the value of the 'access_token'
                        accessToken = HttpUtility.ParseQueryString(sr.ReadToEnd()).Get("access_token"); 
                    }
                        //TODO
                        // Add to the accessToken for the Logged in User.Identity to a FBUSERS Model
                        // WHen someone Logs in Check to see if they are also in FB
                        // ON Login Page add option to login with FaceBook
    
    
                      return View();
    
                    }
                    catch (Exception exp)
                    {
                        // try to get token failed
    
                    }
                }
                else
                {
                     // state var form FB did not match state var sent
    
                }
                return View();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.