Carl Mark
Carl Mark

Reputation: 371

How to authorize facebook app with javascript

I created this simple code:

FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        alert('connected');// connected

      } else if (response.status === 'not_authorized') {

      alert('not_authorized');// not_authorized


      } else {
        alert('not_logged_in');// not_logged_in
        login();
      }

And here is the login function, but if I use the login() in the not_autorhized section, the window appear and immediately close (automaticaly)

function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected            
        } else {
            // cancelled
        }
    });
}

But how to authorize the app in javascript?

here is my full code: http://pastebin.com/Qv9ayb9V

Upvotes: 2

Views: 3034

Answers (1)

dm03514
dm03514

Reputation: 55932

Updated based on your updated information, now it is a shot in the dark...

You have probably already authenticated your app? and are logged in to facebook.

Try going to facebook.com and logging out. (or using FB.logout()) THen log back in to your site. You should be required to login in the popup


Facebook provides step by step guide on their site explaining how to do this.

https://developers.facebook.com/docs/howtos/login/getting-started/

Did you define the login function? It is not provided by facebook:

function login() {
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
        } else {
            // cancelled
        }
    });
}

FB.login takes an additional param with some config options: one is the scope

{scope: 'email,publish_actions'}

   function login() {
        FB.login(function(response) {
            if (response.authResponse) {
                // connected
            } else {
                // cancelled
            }
        }, {scope: 'email,publish_actions'});
    }

Upvotes: 2

Related Questions