YAY! The same problematic problem (well, the same problem, but the same desired functionality) bothered me very much, but finally, after HOURS research on various sources, I understood the solution!
first
var data = FB.api(
It is not right! Since all fb requests are executed asynchronously, and the only way to get data values is inside this request after it is executed. ex
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); }); } });
2. Your permission request is called blocked by chrome for security reasons (firefox allows other browsers to allow or not)
"A single popup can only be enabled if it is opened from a user action event such as .onclick." This way you can attach a function to the .onclick event.
3rd My solution to check if the user has the necessary permissions to use your application:
FB.getLoginStatus(function(response) { if (response.status.toString().indexOf("connected")>-1) { initAll(); } else { requestPermisions proceedure }
This function checks if the user is connected and has granted permissions for your application in another way. response.status = "unknown".
Now....
The problem with the popup permission block has 2 solutions.
1st solution = attach the FB.login () function to the onclick event of the .Ex button.
ifUserNotgrandedPermisions{document.getElementByid("aLogInButton").onclick = function(){ FB.login(....blah blah blah); };
The second solution, and the one I implemented, redirects the iFrame to the request resolution page and does not pop up
Below is a complete solution that checks if a user is registered and provided with perms ... if he does not ask the user to log in and then ask for permissions (if you are logged in, just ask perms) (if he has only logs )
FB.init({appId: 'YourAPPID', status: true, cookie: true, xfbml: true, oauth : true}); FB.getLoginStatus(function(response) { if (response.status.toString().indexOf("connected")>-1) { initAll();
//top.location changes the browser url and NOT the iframe url
// This url was specifically created for the perms request for your application. You change permissions and your appID
// redirect_uri = Change this to the application canvas page
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";}});};