Redirect in facebook iframe app on multiple pages

small problem with my iframe facebook app. I want to use the app on many fb pages (so I won't know the exact urls of the FB pages) in a tab. But there is a problem with the redirect after the app asks for the permissions. Instead of the fb page, it redirects user to my canvas URL, and that is wrong! How to solve it?

Upvotes: 0

Views: 489

Answers (2)

Jan Olaf Krems
Jan Olaf Krems

Reputation: 2294

If you only ask once for login/permissions (this won't handle getting permissions when needed), something like this should work:

function withLogin(callback) {
  var ifLogin = function(response, true_cb, else_cb) {
    if(response.authResponse)
      true_cb(null, response);
    else
      else_cb(true, null);
  };

  FB.getLoginStatus(function(response) {
    ifLogin(response, callback, function(err, response) {
      FB.login(
        function(response) {
          ifLogin(response, callback, callback);
        },
        { scope: "email,user_photos" }
      );
    });
  });
}

...
window.fbAsyncInit = function() {
  ...
  withLogin(function(err, response) {
    if(err)
      alert("This only works if you log in!");
    else
      alert("UserId: " + response.authResponse.userID);
  });
};

Upvotes: 0

Mehul Hingu
Mehul Hingu

Reputation: 1240

Dont use the redirect method for fan pages aka Tabs ,just call the following method in java script to get permission.

 function getPermission(){

     FB.ui({

       'method': 'permissions.request',

       'perms': 'publish_stream,email,user_photos',



      },

  function(response) {

    if (response.perms != null) {

 // user is already connected
token=response.session.access_token;
uid=response.session.uid;


     }

     else if(response.status=="connected")
     {
token=response.session.access_token;
uid=response.session.uid;

// new user is now connected

     }




            else

            {

// user has not given a permission hence not connected.

                }

 });

return false;

}

Upvotes: 1

Related Questions