Wednesday 15 August 2012

javascript - why do else cases in fbAsyncinit/fb.Event.subscribe not work? -


I'm wondering why it looks like "else if" of response.status === 'authorized No '' and "other" cases ("unknown", i.e. the user is not logged into Facebook) is not being executed. When I am logged in to my app, testAPI () is accordingly called in response.stats === 'Connect' . However, when I open the secret mode in Chrome, in other cases the testAPI () function is not being called, why do anyone know?

  window.fbAsyncInit = function () {FB.init ({appId: 'appnumberhere', // app id channel url: '//localhost/appname/channel.php', // channel File status: true, // check login status cookie: true, enable cookies to allow // server to use session xfbml: true // parse xfbml}); FB.Event.subscribe ('auth.authResponseChange', function (response) {if (response.status === 'connect') {testAPI (); // works} and if (response.status === 'not_authorized' } {TestAPI (); // is not called.Nothing in the console. FB.login ();} and {testAPI (); // nothing is called.in nothing in the console.FB.login () ;}}); }); // async init function   

testAPI function:

  function testAPI () {console.log ('Welcome! Getting Your Information .... '); FBP ('/ m', function (feedback) {console.log ('good to see you,' + response.name + '.');}); }   

As a side note, if I have not been logged in, then I can not even see a Facebook login dialog, which I think is FB.Login () Is to invite.

Additional side note

In addition, oddly, give me & lt; Script src = "// connect.facebook.net/en_US" & lt; Script & gt; (Function (d) {var js, .... and lieutenant; / script> in /all.js"></script> and my app to work In my channel file for. Otherwise, some parts do not load. It is not certain that it can be related, but it is very strange.

auth.authResponseChange and auth.statuschange . When a user loads the page, using Ta is closed in "unknown" status, but once the FB indeat is called from status: true , then the Facebook checks login status and determines that the user is not logged in It is also called "unknown" state! Technically, there is no change in the state, so state-change callback is not called. (It seems like a major API design fault, in particular Own self The sample code does not work.)

A solution, which is an accepted answer to that question, is to set the status check incorrectly in FB.init , and instead Manually check the status using the FB.getLoginStatus () so that we can answer it myself if the user is not logged in, then subscribe to the login event. If the user is already logged in, then it is very good

Here the code I am using is login () and logout () The function I have determined is that the log-in is not presenting the parts of the page and the log-in is not located logout () displays a login button, while login () Displays user-specific information

  FB.init ({appId: '...', Channel URL: window.location.protocol + '' '+' window.location Host + '/channel.html', position: wrong, [... other settings ...]}); FB.getLoginStatus {function (response.status === 'connect') {login ();} Other {FB events subscriptions ('auth.login', function (feedback) {window.location. Load (); Login ();}); Logout ();}}}   

Note that window.location.reload (); that In the situation where the user was not originally logged in and then logged in himself. Similar One frame blocked ... In my case a http: // vs. https: // match was not found. If you need it in your case then see: If you are still blocking a one frame ... error, this is due to the way you configure your app settings in Facebook Try entering the http: // localhost: 8080 / under the "Website with Facebook login" site URL and visit that site to view your app.

No comments:

Post a Comment