2013-07-04 2 views
2

railscast를 따라 내 사이트에 "Facebook 로그인"기능을 추가했지만 로그인하는 데 문제가 없습니다.FB.getLoginStatus가 Chrome에서도 샌드 박스 사용 중지되지 않음

(function() { 
    jQuery(function() { 
    $('body').prepend('<div id="fb-root"></div>'); 
return $.ajax({ 
    url: "" + window.location.protocol + "//connect.facebook.net/en_US/all.js", 
    dataType: 'script', 
    cache: true 
}); 
}); 

window.fbAsyncInit = function() { 
FB.init({ 
    appId: 'xxxxxomittedxxxxx', 
    cookie: true, 
    status: true, 
    xfbml: true, 
    oauth: true 
    }); 
$('#sign_in').click(function(e) { 
    e.preventDefault(); 
    return FB.login(function(response) { 
    if (response.authResponse) { 
     return window.location = '/auth/facebook/callback'; 
    } 
    }); 
}); 
return $('#sign_out').click(function(e) { 
    FB.getLoginStatus(function(response) { 
    if (response.authResponse) { 
     return FB.logout(response.authResponse); 
    } 
    }); 
    return true; 
}); 
}; 

}).call(this); 

나는 FB.getLoginStatus을 알고 그 이유는 그러나 시도가 로그 아웃 할 때, FB.getLoginStatus이 (다른 토론에서 제안) 나 페이스 북 개발자 앱 설정에서 샌드 박스 모드를 해제하는 경우에도 화재를 가진 적이 없어 보인다 에서 결코 (또는 작동하지 않습니다) 내가 함께 몸을 바꿀 수 있습니다 :

FB.getLoginStatus(function(response) { 
    return alert("I am here!"); 
    }); 

와 "sign_out"버튼을 클릭하면서 내 경고를 볼 수 없습니다.

동일한 동작을하는 Chrome과 Firefox를 모두 실행하고 있습니다. 아무도 내가 놓친 것을 발견하는 데 도움이 될 수 있습니까? 고마워.

날 '동작'에 대한보다 구체적인 설명하자 나는 발생했습니다

  1. 기호에 페이스 북으로 처음 mysite.com에서 페이스 북 로그인 창이 팝업 및 이메일과 비밀번호를 요청하고, 내가 할 수있는 것 내 사이트에 완벽하게 로그인하고 정상적으로 작동하십시오.
  2. 그런 다음 mysite.com/users/1에서 sign_out 버튼을 클릭하면 로그 아웃하는 것처럼 보입니다.
  3. mysite.com에서 Facebook으로 다시 로그인하십시오. 이제 더 이상 Facebook 로그인 창을 팝업으로 표시하지 않고 이메일과 비밀번호를 묻지 않고 mysite.com/users/1에 직접 로그인하십시오!
  4. 다른 브라우저 창을 열고 facebook.com으로 이동하여 거기에서 로그 아웃하면 mysite.com에서 Facebook으로 로그인하면 Facebook 로그인 창이 팝업되고 이메일과 비밀번호를 묻습니다. 내가 행동하는 내 사이트를 싶습니다

:

사람이 될 수있다 "때 mysite.com/users/n에서 로그 아웃하고 mysite.com에서 다시 페이스 북으로 로그인 페이스 북 로그인 창이 팝업된다" 도움이 필요 하신가요? 고마워.

편집 :

추가 조사가 여전히 수 있습니다 "루트"원인을 발견 부호를이 경로에있는 기호의 다른 경로 (또는 페이지) 아래에 있으며 FB.getLoginStatus 단지에서 화재가 될 수 없습니다 mysite.com/signout. Firebug의 오류 메시지는 "지정된 URL은 응용 프로그램 구성에서 허용되지 않습니다."라는 오류 메시지가 표시됩니다. 해당 URL 중 하나 이상이 응용 프로그램의 설정에 허용되지 않았으며 웹 사이트 URL 또는 Canvas URL과 일치해야합니다. 응용 프로그램 도메인 중 하나의 하위 도메인. "

경로 문제인 것을 증명하기 위해 "페이스 북 로그인 웹 사이트"에 지정된 루트 경로 mysite.com 인 로그인 경로와 동일한 경로 (페이지)에 로그 아웃 링크를 둡니다. 모든 것이 작동합니다 예상대로 로그 아웃 할 수 있습니다 다음 sign_out의 JS가 FB.logout가 매개 변수로 기능을 기대하기 때문에 FB.logout (response.authResponse) 캐치되지 않는 [개체 개체] 오류를 제거하는 개정 그런데

<%= link_to "sign out facebook", "#" , id: "sign_out" %> 

을 :

return $('#sign_out').click(function(e) { 
    FB.getLoginStatus(function(response) { 
    if (response.authResponse) { 
     FB.logout(); 
    } 
    }, true); 
}); 
}; 

그래서 결론은 FB.getLoginStatus가 여전히 가질 수 있습니다. 경로에 로그인하는 것과 다른 경로에서 호출을 처리 할 수없는 버그. (크롬, 파이어 폭스, 사파리로 테스트를 해봤는데 IE10에서는 모두 동일하게 동작하지만 사실은 아닙니다.어떻게 든 IE10은 다른 경로에서 로그 아웃합니다.)

비슷한 문제가있는 사람의 의견이 있으십니까? 제발 조언. 대단히 감사드립니다. FB dev에 문서에 명시된 바와 같이 getLoginStatus에 두 번째 매개 변수로 진정한 추가

답변

0

봅니다 :

FB.getLoginStatus(function(response) { 
    // this will be called when the roundtrip to Facebook has completed 
}, true); 

이 캐싱을 피해야한다. 또 다른 옵션은 이벤트를 구독 할 수 있습니다 :

FB.Event.subscribe('auth.login', function(response) { 
    // do something with response 
}); 

모든 코멘트

here에서 당신은 질문이있는 경우.

편집 : 나는, 스크립트 조금 수정 불필요한 코드 부분을 제거

. 필요하지 않은 반품이 너무 많았습니다. 이 수정 된 스크립트 내에서 로그 아웃을 시도했지만 필요에 따라 작동합니다. 이벤트 구독은 확인 용입니다.

<head> 
    <title>Exam entry</title> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
</head> 
<body> 
    <div id="fb-root"></div> 

    <input type="button" value="Sign in" id="sign_in" /> 
    <input type="button" value="Sign out" id="sign_out" /> 

    <script type="text/javascript"> 
     window.fbAsyncInit = function() { 
      FB.init({ 
       appId: '586844044669652', 
       cookie: true, 
       status: true, 
       xfbml: true 
      }); 


      // 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. 
        testAPI(); 
       } /*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. 
        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(); 
       }*/ 
      }); 


      $('#sign_in').click(function (e) { 
       e.preventDefault(); 
       FB.login(function (response) { 
        if (response.authResponse) { 
         //return window.location = '/auth/facebook/callback'; 
        } 
       }); 
      }); 
      $('#sign_out').click(function (e) { 
       FB.logout(function (response) { 
        console.log("Here logout response", response); 
       }); 
      }); 

     }; 

     // 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() { 
      console.log('Welcome! Fetching your information.... '); 
      FB.api('/me', function (response) { 
       console.log('Good to see you, ' + response.name + '.'); 
      }); 
     } 

     // 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)); 
    </script> 
</body> 
+0

제안 사항을 보내 주셔서 감사합니다. 아직도 응답을 가지고 무언가를 할 수는 없습니다. 제 경우에는 FB.logout을 할 수 없습니다. –

+0

도움을 주셔서 감사합니다. 나는 너의 js을 시도했다. 이전과 동일하게 작동하고 액세스 토큰없이 FB.logout()이라는 추가 오류 메시지가 표시됩니다. –

+0

전체 페이지를 보여줄 수 있습니까? – EnterSB

관련 문제