我使用FB登錄我的演示站點連接: 我用這個代碼:Facebook登錄連接狀態
window.fbAsyncInit = function() {
try{
FB.init({
apiKey: '<MY APP KEY>',
channelUrl : 'www.google.com'
});
FB.getLoginStatus(function(response){
loginHandler();
});
}catch(error){}
};
function loginHandler(success,fail)
{
try{
if(success){
alert('i am if');
FB.api('/me', function(response,fail) {
alert("first name == " + response.first_name + "\n ln === " + response.last_name);
});
}
}catch(error){}
}
$('#login').bind('click', function(response) {
try{
FB.login(loginHandler, {scope: 'email,user_likes'});
}catch(error){}
});
$('#logout').bind('click', function() {
try{
FB.logout(function(response){});
}catch(error){}
});
現在我的問題是,警報(「我如果」);顯示每次我是否通過正確憑據到facebook或不和警報(「first name ==」+ response.first_name +「\ n ln ===」+ response.last_name);顯示undefined當用戶通過時錯誤憑據並顯示用戶回來時傳遞的正確信息正確信息。
一個可能的選擇是檢查像if(response.first_name!=undefined){blah blah....}
但它是檢查驗證的正確方法嗎?
請一些線索....
它爲我工作,謝謝....非常感謝 –