2012-02-05 115 views
3

假設我有一個使用JS SDK運行的Facebook應用程序。facebook check在用戶登錄後要求額外的權限

第一個用戶點擊LINK A,然後我打電話給FB.login()詢問「email」權限。

<a href="#" onclick="doLogin();>LINK A</a> 
<script> 
function doLogin() { 
FB.login(function (res) { 
//res contains authResponse, i.e. the user is logged in. 
}, { scope : 'email'} }); 
} 
</script> 

然後我會檢查authResponse來檢查用戶是否登錄。

if(res.authResponse) { 
//User logged in 
} else { 
//User NOT logged in 
} 

現在,讓我們說,在LINK B,我要問的「user_birthday」權限:

FB.login(function (res) { 
//Now res.authResponse is set even if user did NOT grant access to the "user_birthday" permission 
}, { scope : 'user_birthday'} }); 

但是當「user_birthday」的請求時用戶已經登錄到應用程序 - 因此authResponse將被設置,而不管用戶是否被授予訪問額外權限,或單擊取消。

有沒有辦法檢查用戶是否給了額外的權限?

我知道我可以在/我/權限的API上查找 - 但我不知道是否有辦法在FB.login()回調中做到這一點?

回答

2

是的,使用該用戶訪問令牌,查詢me/permissions

FB.api('me/permissions',function(permsArr){ 
    var canGetBirthday = PermissionExists(permsArr, 'user_birthday'); // write your own PermissionsExists parser.... 
}); 
+0

沒有額外的查找方法嗎? – jack 2012-02-05 00:46:08

+0

不是我所知道的。你可以嘗試在Facebook上返回一個'console.dir(response);',但我懷疑任何沿着權限授予的內容都會在那裏。 – DMCS 2012-02-05 00:50:28

相關問題