Facebook C# SDK Can never get IsAthorized() to return true
I have been trying like heck to get this to work. I am pretty confident that I have my Facebook app setup correctly and that I am using the correct appId and appSecret. When I debug the Login.aspx and put a breakpoint on the
if (response.session)
I see that it is filled out properly with the access_token. But when it hits the codebehind the
if (auth.IsAuthorized())
is always false! Here is the code on the aspx page which is just from the sample.
<h2>Log In </h2>
<p>
<fb:login-button autologoutlink="true" perms="email,user_birthday,offline_access,status_update,publish_stream"></fb:login-button>
</p>
<div id="fb-root">
</div>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
FB.init({ appId: '<%: Facebook.FacebookContext.Current.AppId %>', status: true, cookie: true, xfbml: true });
FB.Event.subscribe('auth.sessionChange', function (response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
window.location.reload();
} else {
// The user has logged out, and the cookie has been cleared
//src="http://connect.facebook.net/en_US/all.js"
}
});
</script>
I even tried using this in the codebehind of the login page
public FacebookSession CurrentSession
{
get { return (new CanvasAuthorizer()).Session; }
}
if (C开发者_如何学CurrentSession != null)
{
Facebook.FacebookClient fbApp = new FacebookClient(CurrentSession.AccessToken);
dynamic result = fbApp.Get("/me");
}
And CurrentSession is always null as well.
I have been racking my brains on this and googleing like heck. And, again, I feel I have the FB app set up properly. Oh, I am using the latest download, 5.0.03 beta. Thanks!
Are you testing your application from the domain you registered your FB app with? If not, then that might be your problem - I'm pretty sure that you need to be on the registered domain in order for the authorization to succeed.
@HOCA I am testing this thru my http://localhost:5000 which is how I have it set up in Facebook. Again, when I set a breakpoint on the
if (response.session)
on the login.aspx page (not the codebehind) I am getting a fully populated session object with all the goodies in there. It is just when it hits the codebehind that nothing ever gets "authorized". And I have used this Facebook app very successfully with other Facebook asp.net code but I cannot ever get this SDK code to work.
精彩评论