Problem Authenticating C# Facebook Example
First allow me to apologies for my lack of knowledge on this subject, but I am hoping to build this up!
I开发者_StackOverflow中文版 am having a lot of difficulty with the Facebook C# API. I am attempting to use the sample included in the download, "CSPASPNETWebsite." I have added my application ID and secret to the config file, and can run the site. I navigate to the login page and click the Facebook button, and then confirm that I wish to allow the app to access my data. However after doing this, I am never getting a positive result on being authenticated.
I have tried several things and keep having this problem, I was wondering if anyone else had had similar or knew what might be causing the problems. I would include code but it is exactly the example project with the config file adapted to my app.
Thanks for reading and thanks in advance for any responses.
EDIT: I should also note that I am developing locally, using Visual Studio 2010 and SDK version 5.0.3 (Beta). I have a suspicion that my problems may be due to the problem with cookies mentioned here however I cannot access IIS to try their suggestion
Rob pointed out correctly that my opinion was wrong. Infact I tryed playing a bit with the sample that he is mentioning and I have found that something weird happens navigating the same page with different browsers. If I run the sample and browse it by google chrome it works as expected. Browsing it by ie 8 it doesn't work.
Moving the Fb:button after the script initialization it works in ie 8 too.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Log In
</h2>
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
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
alert("right");
window.location.reload();
} else {
alert("wrong");
// The user has logged out, and the cookie has been cleared
}
});
</script>
<p>
<fb:login-button></fb:login-button>
</p>
</asp:Content>
My original answer: I believe your problems are not your fault. It seems those examples are out of date. The one you are mentioning is built on top classes deleted from the last version of the sdk. Lately the sdk has been completely changed and code examples are not updated. You can see here, for the one you are mentioning how many changes has been made:
http://facebooksdk.codeplex.com/SourceControl/list/changesets
for instance
- updated CSASPNETWebsiteregistrationForm to use Request.GetFacebookSignedRequest() method
- CSASPNETWebsite to use FacebookAuthorizer instead of Authorizer
If you would like to see that example working I think you should remove references to the last build of the sdk and reference the old one.
I dont raccomand it.
精彩评论