The fb.Login () window closes immediately and returns 'not_authorized'

I have FB login enabled on my site with FB JDK. When I use it, it works fine: a dialog box opens, I enable, and authResponse - as expected. When another user uses it (who has not yet authorized the application, but has been registered in FB), the login dialog appears for a short second and instantly disappears, and the response object has the status not_authorized . Any ideas as to why the dialog might not ask the user for authorization?

In my layout (Haml):

 %body #fb-root :javascript window.fbAsyncInit = function() { FB._https = false; FB.init({ appId : <App ID> status : true, cookie : true, oauth : true, xfbml : true }); FB.getLoginStatus(function(response) { if(window.reportFBstatus) { reportFBstatus(response); } }, true); }; // Load the SDK (function(d){ var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); 

Login link:

 %a{href: '#', onclick: 'FB.login(window.reportFBstatus, {scope: "user_about_me"})'} 

In Coffeescript:

 window.reportFBstatus = (response) -> $.ajaxSetup({ headers: 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content') }) console.log response # always shows status=not_authorized for other users if response.status is 'connected' auth = response.authResponse $.post('/login', {fb_id: auth.userID, fb_token: auth.accessToken}, (data) -> window.currentUser = data ) 
+7
source share
1 answer

The solution that worked for me was actually a bone - I forgot to change the application from sandbox mode to live mode in the developer apps console on Facebook (click your application on the left). Alternatively, I could add people with whom I want to register as developers or testers.

Hope this helps others!

+15
source

All Articles