2013-07-29 4 views
0

처음 사용자가 앱에 액세스하면 모든 것이 정상적으로 작동합니다. 사용자는 내 앱을 인증하는 질문을 가진 팝업을 얻습니다. 그런 다음 다음 세션 (예 : 새로 고침)에서 즉시 팝업을 닫는 빈 팝업이 표시됩니다.로그인 후 빈 Facebook 팝업

필자는 페이스 북이 새로운 액세스 토큰을 요구한다고 생각하지만 문제는 사용자 친화적이지 않다는 것입니다. 팝업이 열리고 닫힐 때 사용자는 뭔가 잘못되었거나 뭔가를 놓친다 고 생각합니다.

window.fbAsyncInit = function() { 
    FB.init({ 

    appId  : '', // App ID 
    channelUrl : '', // Channel File 
    status  : true, // check login status 
    cookie  : true, // enable cookies to allow the server to access the session 
    xfbml  : true // parse XFBML 
    }); 

    // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired 
    // for any authentication related change, such as login, logout or session refresh. This means that 
    // whenever someone who was previously logged out tries to log in again, the correct case below 
    // will be handled. 

    FB.Event.subscribe('auth.authResponseChange', function(response) { 
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') { 
     // The response object is returned with a status field that lets the app know the current 
     // login status of the person. In this case, we're handling the situation where they 
     // have logged in to the app. 

     if(accessToken) 
     { 
     //console.log("Connected WITH accesToken"); 
     testAPI(); 

     } 
     else{ 
      // console.log("Connected WITHOUTaccesToken"); 
    FB.login(function(response) { 
      // handle the response 
      uid = response.authResponse.userID; 
    accessToken = response.authResponse.accessToken; 
    //console.log(uid); 
    //console.log(accessToken); 
     }, {scope: 'friends_location, user_location, user_relationships'}); 

    } 


    } else if (response.status === 'not_authorized') { 
     // In this case, the person is logged into Facebook, but not into the app, so we call 
     // FB.login() to prompt them to do so. 
     // In real-life usage, you wouldn't want to immediately prompt someone to login 
     // like this, for two reasons: 
     // (1) JavaScript created popup windows are blocked by most browsers unless they 
     // result from direct interaction from people using the app (such as a mouse click) 
     // (2) it is a bad experience to be continually prompted to login upon page load. 

    //alert("You're logged in on FB but not on the APP"); 
     FB.login(); 

    } else { 
     // In this case, the person is not logged into Facebook, so we call the login() 
     // function to prompt them to do so. Note that at this stage there is no indication 
     // of whether they are logged into the app. If they aren't then they'll see the Login 
     // dialog right after they log in to Facebook. 
     // The same caveats as above apply to the FB.login() call here. 

// FB.login(); 
     //alert("You're offline on FB"); 
      FB.login(); 
    } 
    }); 




    }; 

    // Load the SDK asynchronously 

    (function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 


    // Here we run a very simple test of the Graph API after login is successful. 
    // This testAPI() function is only called in those cases. 
    function testAPI() { 

    FB.api('/'+uid+'/friends?fields=name,location,picture&accesstoken='+accessToken, function(response) { 

    } 


     //<img border="0" src="console.log(response.data[0].picture.data.url)"> 
     } 

    }); 

    } 

    //Logout 
    function fbLogout() { 
     //FB.init(); 
     FB.logout(function (response) { 
      //Do what ever you want here when logged out like reloading the page 
      //window.location.reload(); 
     }); 
    } 

가 어떻게이 빈 팝업을 방지 할 수 있습니다 : 여기

enter image description here

코드인가?

답변

0

FB.login, 즉 FB.getLoginStatus을 명시 적으로 호출합니다.이 대화 상자는 로그인 대화 상자의 래퍼입니다. 이런 이유로 당신은 항상 팝업을 얻는다.

대신 getLoginStatus를 먼저 호출하고 실패 할 경우에만 login을 트리거하는 버튼을 제시하십시오.

+0

나는 완전히 이해하지 못한다. 실패하면 (인증 또는 오프라인 없음) FB.login을 수행합니다. 거기에 버튼으로 트리거하는 것과 함수를 직접 호출하는 것의 차이점은 없습니다. 그리고 연결되면 항상 액세스 토큰을 얻기 위해 범위로 추가 로그인을해야합니다. 또는 1 개의 큰 FB.login 함수를 만들고 FB.Event.subscribe (3x를 연결하여 액세스 토큰을 얻으려면, 인증 안 함, 오프라인)에서 참조하는 것이 더 좋습니다. – Shouse

관련 문제