如何在Chrome中询问publish_stream权限

时间:2011-12-28 12:46:51

标签: javascript facebook facebook-javascript-sdk facebook-authentication

如何申请facebook权限?

使用FB.login

时,Chrome会阻止弹出窗口并发出大量警告
function askPermission() {
    FB.login( function(response) {
        if(response.authResponse) {
            // Do what I want to do
        }
    }, {scope:'publish_stream'});
}

相反,我尝试了How to set permission dialog for post message on wall

function askPermission(appid, redirect_uri, response_type, scope, callback) {
     // Redirect the user back after authorization
     var path = 'https://www.facebook.com/dialog/oauth?';
     var queryParams = ['client_id='+appid, 'redirect_uri='+encodeURI(redirect_uri), 'response_type='+response_type, 'scope='+scope];
     var query = queryParams.join('&');
     var url = path + query;
     top.location.href = url;
}

但它也不起作用。我收到了一条错误消息,例如

“YourApp中发生错误。稍后再试。”

编辑: 即使我尝试过,Chrome仍然会抛出大量“不安全的JavaScript尝试访问带URL的框架”:

<input type="button" value="Convidar amigos" class="verde" onclick="FB.login(function(response){ if(response.authResponse){post();} }, {scope:'email,publish_stream'});"/>

1 个答案:

答案 0 :(得分:0)

您应该只在用户互动(点击,提交等)上调用FB.login,否则它将在大多数浏览器中被屏蔽。您看到的错误是因为JS-SDK无法与被阻止的窗口进行交互。