[英]Check if a user is logged in to Facebook
我正在嘗試使用JavaScript檢查用戶是否已登錄Facebook(是否已登錄,與我的應用程序無關)。
我嘗試在FB.init之后使用以下代碼:
FB.getLoginStatus(function(response) {
alert(response.status);
});
edge.create工作正常。
有一些技巧可以幫助您,但在您遇到的情況中不起作用。 https://grepular.com/Abusing_HTTP_Status_Codes_to_Expose_Private_Information
這是簡單的示例:
<html>
<head>
</head>
<body>
// At the end of page will be good
<script>
function logged() {
alert('logged');
}
function notlogged() {
alert('not logged');
}
</script>
<script src="http://www.facebook.com/ajax/composer/attachment/question/question.php" onload="logged()" onerror="notlogged()">
</body>
</html>
if (FB.getSession() != null) {
FB.api('/me', function(response){
alert ("Welcome " + response.name);
})
}
需要注意的是:用戶需要授權您的應用程序才能檢測是否已登錄。 我相信,如果沒有此api,沒有它就無法檢測到它:您可以添加like按鈕等等,但不能與fb狀態交互。
FB.getLoginStatus(function(response) {
if (response.authResponse) {
// alert('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
alert('Good to see you, ' + response.name + '.');
});
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.