FB如果没有会话可用,JavaScript JavaScript iframe应用程序不会自动重定向到FB登录页面 [英] FB JavaScript iframe application is not auto redirecting to FB login page if no session available

查看:148
本文介绍了FB如果没有会话可用,JavaScript JavaScript iframe应用程序不会自动重定向到FB登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用JavaScript开发Facebook的iframe应用程序..问题是当用户点击应用程序URL https://apps.facebook.com/projectanida/ 我希望用户看到应用程序主页面,如果它们已经登录到fb,如果没有用户会话可用,那么用户应该被自动定向到FB页面,要求凭据登录到Facebook以使用我的应用程序。

I am developing facebook iframe app with JavaScript.. the problem is when the user hits the app URL https://apps.facebook.com/projectanida/ I want users to see the application main page if they are already logged into fb and if there is no user session available then the user should be automatically directed to FB page asking for credentials to log into Facebook to use my app.

这是代码:

var href = "https://projectafacebook.appspot.com/fb/";
var appliId = "165346656890746";

window.fbAsyncInit = function() {
    FB.init({
        appId: '165346656890746',
        status: true,
        // check login status
        cookie: true,
        // enable cookies to allow the server to access the session
        xfbml: true // parse XFBML
       // sizeChangeCallback();

    });

  FB.Event.subscribe('auth.sessionChange', function (response) {
                               if (response.session) {
                                   //user is logged in!
                                   alert("//user is logged in!");
                                 //  window.location = document.URL;
                               } else 
                               {
                                   alert("//user is not logged in!");
                            windows.top.location.href = 'https://graph.facebook.com/oauth/authorize?client_id=' + appliId + '&redirect_uri=' + href + '&display=page';

                                   }
                            }); 
};
 FB.getLoginStatus(function(response) {
            if (response.session) {
                //alert("session true");
                //$("#fb-root").show();
            } else {
                top.location.href = 'https://graph.facebook.com/oauth/authorize?client_id=' + appliId + '&redirect_uri=' + href + '&display=page';
            }
        });

如果零件工作正常,但当其他部分出现时,它显示fb登录页面,但在蓝色栏下方的fb页面,它显示我的应用程序,即使没有会话可用也是可以访问的...它在Chrome和IE8中有效,但从未在opera n firefox。

the if part works fine but when the else part come it shows fb login page but below the blue bar of fb page it shows my application and is also accessible even if no session is available... it works fine in chrome and IE8 some times but never in opera n firefox.

如果我们登录该页面,它仍然直接在我的应用页面在fb,但画布大小是固定的,我的应用程序被剪切,如果我先登录,然后打我的应用程序URL,那么应用程序工作正常,画布大小也精细。请帮忙!

and if we login on that page it still direct to my app page in fb but the canvas size is fixed and my app got cut where as if i login first and then hit my app URL then the applications works fine and canvas size is also fine. please help!

推荐答案

不要再使用 auth.sessionChange auth.statusChange auth.authResponseChange

当您发现没有会话而不是使用 FB.login()

Also is there any reason you're redirecting to a specific URL when you find there is no session instead of using FB.login()?

尝试这样:

FB.Event.subscribe('auth.statusChange', handleUserStateChange);
FB.getLoginStatus(handleUserStateChange);

function handleUserStateChange(response) {
    // User is not logged into Facebook OR hasn't authenticated app
    if(!response.authResponse) {
        // http://developers.facebook.com/docs/reference/javascript/FB.login
        FB.login(function(response) {
            if(response.authResponse) {
                window.location.reload();
            }
        });
    }
}

这篇关于FB如果没有会话可用,JavaScript JavaScript iframe应用程序不会自动重定向到FB登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆