Check Facebook login status and get session information using Facebook C # SDK

On the interface, I initialized FB and login using:

window.fbAsyncInit = function () { FB.init({ appId: @facebookAppId, // App ID status: true, // check login status cookie: true, // enable cookies to allow the server to access the session xfbml: true, // parse XFBML oauth: true }); // Additional initialization code here FB.Event.subscribe('auth.login', function () { window.location = "/facebookPostAuth.aspx"; }); FB.Event.subscribe('auth.logout', function (response) { window.location = '/logout'; }); // Hack to fix http://bugs.developers.facebook.net/show_bug.cgi?id=20168 for IE7/8/9 FB.UIServer.setLoadedNode = function (a, b) { FB.UIServer._loadedNodes[a.id] = b; }; }; // Load the SDK Asynchronously (function (d) { var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; } js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); } (document)); 

On an internal server, how to check if a login session exists using the Facebook C # SDK?

This is as much as I have, but I'm not sure how to transfer the APP ID / Secret to get additional information (for example, the email that I included in the registration area):

  var client = new FacebookClient(); dynamic me = client.Get("me"); string firstName = me.first_name; string lastName = me.last_name; string email = me.email; 
+4
source share
1 answer
 var client = new FacebookClient(appID, appSecret); 

or

 var client = new FacebookClient(accessToken); 

You can capture the client access token using the javascript SDK and transfer it to the server in a hidden form field (regular or ajax), or the C # SDK provides what it finds in the cookie and / or signed request via FacebookWebContext.Current.AccessToken. In the past, I found some timing issues where Facebook did not update the cookie with a new token access signal / signed request in a timely manner, so I get it in Javascript and send it to the server.

0
source

Source: https://habr.com/ru/post/1385027/


All Articles