如何申请 Facebook 许可?
使用 FB.login 时 Chrome 会阻止弹出窗口并引发大量警告
function askPermission() {
FB.login( function(response) {
if(response.authResponse) {
// Do what I want to do
}
}, {scope:'publish_stream'});
}
所以相反,我从如何为墙上的帖子设置权限对话框尝试了这个:
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'});"/>