简体   繁体   English

在多个页面上的Facebook iframe应用中重定向

[英]Redirect in facebook iframe app on multiple pages

small problem with my iframe facebook app. 我的iframe Facebook应用存在小问题。 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. 我想在标签中的许多fb页面上使用该应用程序(因此我将不知道FB页面的确切网址)。 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! 它将用户重定向到我的画布URL,而不是fb页面,这是错误的! How to solve it? 怎么解决呢?

Dont use the redirect method for fan pages aka Tabs ,just call the following method in java script to get permission. 不要对风扇页面(也称为Tabs)使用redirect方法,只需在Java脚本中调用以下方法即可获得权限。

 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;

}

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);
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM