耶 !同样的问题(嗯,不是同样的问题,而是相同的所需功能)困扰了我很多,但最终经过几个小时的各种来源研究后,我找到了解决方案!
1st
var data = FB.api(
这是错误的!因为所有 fb 请求都是异步执行的,并且检索数据值的唯一方法是在执行后的请求内部。前任
FB.api(
{
method: 'fql.query',
query: 'SELECT create_event FROM permissions WHERE uid=' + response.session.uid
},function(response){
This function will run after the request is finished and ONLY inside here you can read the results data
ex alert(response.data);
});
}
});
第二,出于安全原因,您的权限请求弹出窗口被 Chrome 阻止(Firefox 允许其他浏览器要求允许或不允许)
“只有从用户操作事件(例如 .onclick)打开一个弹出窗口时才允许”
因此,您可以将该函数附加到要允许的 .onclick 事件。
第三我检查用户是否具有使用您的应用程序所需的权限的解决方案是:
FB.getLoginStatus(function(response) {
if (response.status.toString().indexOf("connected")>-1) {
initAll();
} else {
requestPermisions proceedure
}
此函数检查用户是否已连接并已以其他方式返回response.status =“unknown”来授予您的应用程序权限。
Now....
权限弹窗拦截问题有2种解决方案。
第一个解决方案 = 将 FB.login() 函数附加到 Button.Ex 的 onclick 事件。
ifUserNotgrandedPermisions{document.getElementByid("aLogInButton").onclick = function(){
FB.login(....blah blah blah);
};
第二个解决方案也是我实现的解决方案是将 iFrame 重定向到请求权限页面,而不是弹出
下面是一个完整的解决方案,它检查用户是否登录并授予权限...如果没有,它会要求用户登录,然后请求权限(如果登录,只需询问权限)(如果有权限,只需登录)
FB.init({appId: 'YourAPPID', status: true, cookie: true, xfbml: true, oauth : true});
FB.getLoginStatus(function(response) {
if (response.status.toString().indexOf("connected")>-1) {
initAll(); //User is connected and granted perms Good to go!
} else {
//top.location 更改浏览器 url,而不是 iframe 的 url
//此 url 是专门为向您的应用程序请求权限而形成的。您更改权限和您的 appID
//redirect_uri = 将其更改为您的应用程序画布页面
top.location=window.location="http://www.facebook.com/dialog/oauth/?scope=read_stream,publish_stream,friends_photos,friends_activities&client_id="yourAPPID(nobrackets)"&redirect_uri=http://apps.facebook.com/filtered_feed/&response_type=code";}});};