On the front-end, I’ve initialised 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 the back-end, how do I check if there is a login session existing using Facebook C# SDK?
This is as much as I’ve got, but I’m not sure how to pass in the APP ID / Secret to get more information (such as email which I’ve inluded in login scope):
var client = new FacebookClient();
dynamic me = client.Get("me");
string firstName = me.first_name;
string lastName = me.last_name;
string email = me.email;
or
You can grab the access token client-side with the javascript SDK and pass it up to the server in a hidden form field (conventional or ajax), or the C# SDK exposes what it finds in the cookie and/or signed request via FacebookWebContext.Current.AccessToken. In the past I have found some timing issues where Facebook did not update the cookie with a new access token/signed request in a timely fashion, which is why I get it in Javascript and post it to the server.