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 comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.