1
votes

I'm trying to switch over to the new Facebook 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);
}());
1
By runs without errors you mean permission dialog is appearing? Are you sure you trigger this Login method after the FB is initialized? Try to delete an app from your app preferences, permissions are cached once you granted them. - serg
It doesn't throw any errors, it runs but does nothing (no prompt.) Tried clearing the browser cache and deleting and re-adding the app but still nothing. - Nick Gotch
How do you trigger it, on some button or on document load? The piece of code you posted is correct, so problem is somewhere else. Maybe post your FB init method and method that triggers login. - serg
Also are you trying this on localhost? If so which url do you set as "connect url" and "base domain" on the "connect" setting tab? - serg
It's triggered from a Silverlight client hosted in the page. A button in Silverlight calls the function. - Nick Gotch

1 Answers

1
votes

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!