我正在研究與Facebook集成的Facebook應用程序,並且正在嘗試獲取用戶的FB會話。據我所知,一個常見的使用場景如下。如果用戶未登錄到Facebook,FB.getLoginStatus不會觸發
- 呼叫
FB.init()
- 呼叫
FB.getLoginStatus
給它一個適當的回調。
我跑了下面的代碼(應用程序ID)。
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
<!--
function init(){
FB.init({
appId : '9999999999999',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : 'http://127.0.0.1:8888/channel.html', // custom channel
oauth : true // enable OAuth
});
alert('going to call FB.getLoginStatus ');
FB.getLoginStatus(function(response) {
alert('whoo hoo!!! getLoginStatus called the callback');
});
}
init();
//-->
</script>
如果用戶已經登錄到Facebook在同一個瀏覽器會話,然後一切正常 - 返回填充_response.authResponse_
。但是,如果用戶未登錄到Facebook,則回調根本不會被觸發。檢查瀏覽器網絡日誌,我看到Facebook返回以下響應(來自http://www.facebook.com/dialog/oauth
的請求?)。
Application Error: There was a problem getting data for the application you requested. The application may not be valid, or there may be a temporary glitch. Please try again later.
我在Chrome和Firefox(Mac)上對此進行了檢查。
更新
我想感謝大家誰回答。
Ben的評論有答案。
謝謝本 - 你救了我很多挫折。
沙盒模式中的應用程序?如果是這樣,似乎有一個錯誤,可能會導致此問題:http://bugs.developers.facebook.net/show_bug.cgi?id=19359 –
您是否使用channelUrl作爲回送,或者只是爲了示例?我不相信環回將適用於該功能。 –
使用channelUrl在[這裏]解釋(https://developers.facebook.com/docs/reference/javascript/FB.init/)。顯然它應該加快加載時間並幫助避免一些問題。 真的不在乎,如果它在我開發的時候做了什麼,應該會在我上線時有所幫助。 –