我想在呈現iframe登錄請求擴展perms之前檢查登錄用戶的權限,但iframe彈出被瀏覽器阻止(ff,chrome測試)。我想避免這種情況,我很確定它是因爲js函數的結果是'嵌套'的 - 我的js聰明是有限的,所以請原諒。Facebook JS SDK:在登錄PopUp之前檢查權限
我在猜測,如果我可以保留原始函數中的所有內容而不會傳遞結果,那麼瀏覽器仍然會將登錄iframe視爲「用戶啓動」並且不會阻止。
但我無法做到這一點 - 例如爲什麼下面的結果是data = undefined。
var data = FB.api(
{
method: 'fql.query',
query: 'SELECT create_event FROM permissions WHERE uid=' + response.session.uid
});
alert(data); // = undefined
我滿當前的代碼是:
<button id="myButton" >Test Publish Event</button>
<script>
$('#myButton').bind('click', function() {
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
FB.api(
{
method: 'fql.query',
query: 'SELECT create_event FROM permissions WHERE uid=' + response.session.uid
},
function(response) {
if(response[0].create_event == 1) {
alert('permission granted');
} else {
alert('permission absent');
FB.login( function(response) {if (response.session) {
handleSessionResponse(response);
if (response.perms) {
// user is logged in and granted some permissions.
// perms is a comma separated list of granted permissions
alert(response.perms);
} else {
// user is logged in, but did not grant any permissions
}
} else {
// user is not logged in
}
}, {perms:'create_event,rsvp_event'});
}
}
);
</script>