Facebook Javascript SDK – Redirect to request for permissions page if the user is not logged in or not subscribed

We can find out the Request for permissions URL of a Facebook application as we discussed previously.
Facebook API – Request for permissions URL

So you can force the user to grant the permissions for your Facebook application by checking their login status and redirecting to the above URL if they are unknown user.

$(document).ready(function() {
  FB.getLoginStatus(function(response) {
    if (response.authResponse) {
      // logged in and connected user, someone you know
    } else {
      // no user session available, someone you dont know
      window.top.location.href = "https://www.facebook.com/dialog/oauth?client_id=[FB_APP_ID]&redirect_uri=[FB_APP_URL]&scope=[PERMISSIONS]";
    }
  });
});

 

Done =)

Reference: Facebook Developers – FB.getLoginStatus

2 thoughts on “Facebook Javascript SDK – Redirect to request for permissions page if the user is not logged in or not subscribed”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s