views:

55

answers:

1

I'm trying to switch over to the new Facebok JavaScript SDK from the old JavaScript library (where I was using Connect) and I'm unable to get the permission dialog to appear. I'm trying to get the permission dialog that's shown under the "Data Permissions" section here.

My old call was this (with appropriate initialization):

FB.Connect.showPermissionDialog('publish_stream');

I tried changing to this (again, with appropriate initialization) but it's not working, it runs without error but the callback is never run:

FB.login(function(response)
{
    if (response.session)
    {
        if (response.perms)
        {
            alert('user is logged in and granted some permissions: ' + response.perms);
        }
        else
        {
            alert('logged in but didnt grant permissions');
        }
    }
    else
    {
        alert('not logged in');
    }
},
{perms:'publish_stream'});

This is the initialization code I'm using:

window.fbAsyncInit = function()
{
    FB.init({appId: 'xxxxxxxx', status: true, cookie: true, xfbml: true});
};
(function()
{
    var e = document.createElement('script');
    e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
}());
A: 

After MUCH tinkering around with the code trying to get this to work I finally found out where the error was. The JavaScript code needs to be place at the end of the HTML, near the </body> tag. I moved it there and everything worked!

Nick Gotch