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 9086421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:29:07+00:00 2026-06-16T21:29:07+00:00

I followed this excellent guide on how to use Facebook login. I modified it

  • 0

I followed this excellent guide on how to use Facebook login. I modified it a little to retrieve the

response.authResponse.accessToken

So, right after this:

// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {

I added this line:

var accessToken = response.authResponse.accessToken;

Now, I can’t find a way to pass this javascript accessToken variable to my server-side C# code.

What I would like is that in the Page_Load() event, it checks if an accessToken is present. If yes, it would not display the “Login with Facebook” div and so I can proceed to use the Access Token from my server-side code.

If the user is not currently logged in, I would like him to log with Facebook and then have my page server-side code to receive the Access Token.

Anybody knows how to do this?

Thank you for your help, I’m losing my mind over this.

PS. I don’t want to redirect the user to another page once he logs in. I just want the page he’s on to know that he is logged in and proceed from here with server-side code.

  • 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-16T21:29:08+00:00Added an answer on June 16, 2026 at 9:29 pm

    In my opinion, the best approach from implementing Facebook Login is to carry out all functionality server side. Using a REST library such as Hammock, you can achieve this.

    Here’s a really useful article on how to implement: http://www2.suddenelfilio.net/2010/09/08/connect-to-facebook-using-asp-net-facebook-graph-api-hammock/

    In addition to that link, here is some code that will point you in the right direction:

    Login Page

    Add an ASP.NET button to this login page with the following click event:

    protected void FacebookLogin_Click(object sender, EventArgs e)
    {
            string fbOuthUrl = "https://graph.facebook.com/oauth/authorize?client_id=<client-id>&redirect_uri=<callback-page-url>&scope=email,publish_actions";
    
            Response.Redirect(fbOuthUrl);        
    }
    

    Callback Page

    As you have seen in the button click event, the redirect_uri is going to point to our callback page. This callback page will carry out all the functionality to get the access token and any other login jobs you need to carry out:

    public partial class FBLoginCallback : System.Web.UI.Page
    {
        private string AccessToken;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(Request["code"]) && !Page.IsPostBack)
        {
            FacebookCallback();
        }
    }
    
    private void FacebookCallback()
    {
        var client = new RestClient { Authority = "https://graph.facebook.com/oauth/" };
        var request = new RestRequest { Path = "access_token" };
    
        request.AddParameter("client_id", ConfigurationManager.AppSettings["facebook.appid"]);
        request.AddParameter("redirect_uri", ConfigurationManager.AppSettings["facebook.login.callbackurl"]);
        request.AddParameter("client_secret", ConfigurationManager.AppSettings["facebook.appsecret"]);
        request.AddParameter("code", Request["code"]);
    
        RestResponse response = client.Request(request);
        // A little helper to parse the querystrings.
        StringDictionary result = QueryStringHelper.ParseQueryString(response.Content);
    
        AccessToken = result["access_token"];
    
        SetUserInformation(AccessToken);
    }
    
        private void SetUserInformation(string sToken)
        {
            var client = new RestClient { Authority = "https://graph.facebook.com/" };
            var request = new RestRequest { Path = "me" };
            request.AddParameter("access_token", sToken);   //Make use of the access token
            RestResponse response = client.Request(request);
    
            JavaScriptSerializer ser = new JavaScriptSerializer();
            var parsedResult = ser.Deserialize<Facebook>(response.Content); //parsedResult will contain basic FB User info
    
        //Redirect to the necessary page
            Response.Redirect("/Default.aspx");
        }
    }
    

    Note: This will require the use of the Hammock REST library as pointed out at the beginning of my post.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed this excellent guide on creating a framework in Xcode for iOS. http://spin.atomicobject.com/2011/12/13/building-a-universal-framework-for-ios/
Googled out- could use some help here. I followed this excellent tutorial here (http://www.malteahrens.com/#/blog/howto-onenote-dev/)
I followed this tutorial to implement facebook into my application. All I want is
I've followed this otherwise excellent tutorial on getting Xen working with Ubuntu but am
i followed this excellent as3 preloader tutorial, and below is the code i have
I followed this article to do automate timestamps in ActiveRecord models. The modified and
I followed this tutorial: http://www.wikihow.com/Generate-Hibernate-Pojo-Classes-from-DB-Tables After I click finish, it looks like something is
I followed this video tutorial but i am stuck.When i click on the login
I followed the excellent tutorial on http://www.jakusys.de/blog/2008/09/grails-and-liquibase-how-to-use/ in regard to my dev database on
After loading the Facebook C# SDK (FacebookWebMVC) library from NuGet, I followed exactly the

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.