views:

32

answers:

0

I want to check permissions of a logged in user before presenting the iframe login to request extended perms, but the iframe popup gets blocked by the browser (ff, chrome tested). I want to avoid this and i'm pretty certain its because the results of the js functions are 'nested' - my js cleverness is limited so excuse me.

I'm guessing that if I can keep everything in the original function without passing down the results the browsers would still see the login iframe as 'user initiated' and not block.

But i'm unable to do this - e.g. why does the following result in data = undefined.

var data = FB.api(
{
method: 'fql.query',
query: 'SELECT create_event FROM permissions WHERE uid=' + response.session.uid
 });
alert(data); // = undefined

My full current code is:

<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>

related questions