call FB.login() after FB.init() automatically

Posted by Tobi Projectx on Stack Overflow See other posts from Stack Overflow or by Tobi Projectx
Published on 2011-09-23T08:54:30Z Indexed on 2012/11/09 5:01 UTC
Read the original article Hit count: 152

i`m developing an app for Facebook.

My Code:

function init() {
    window.fbAsyncInit = function() {
        var appID = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';

        FB.init({ appId: appID, 
              status: true, 
                  cookie: true, 
                  xfbml: true});



        login();
    };

    (function() {
        var e = document.createElement("script"); 
        e.async = true;
        e.src = "https://connect.facebook.net/en_US/all.js?xfbml=1";
        document.getElementById("fb-root").appendChild(e);
    }());
};
function login() {

    FB.login(function(response) {
        if (response.session) {
            if (response.perms) {
                // user is logged in and granted some permissions.
                // perms is a comma separated list of granted permissions
            } else {
                // user is logged in, but did not grant any permissions
            }
        } else {
            // user is not logged in
        }
    }, {perms:'read_stream,publish_stream,offline_access'});
};

I want to call the "init" function and after "init" should call the "login" function (open up the Facebook Login Window) automatically.

But i always get "b is null" FB.provide('',{ui:function(f,b){if(!f....onent(FB.UIServer._resultToken));}}); Error in Firebug.

Can anybody help me? Does anybody have the same problem?

Thanks

© Stack Overflow or respective owner

Related posts about facebook-graph-api

Related posts about login