Search code examples
javascriptfacebookfacebook-graph-apifacebook-javascript-sdkcocoonjs

CocoonJS and Facebook extended permissions


First of all, I'm aware there are plenty of questions and answers relating this topic. However, none of them works for me (maybe because they are old and the methods have become outdated, I don't know)... Let me briefly explain my problem:

I've been trying to login to Facebook with extended permissions on CocoonJS for about two weeks and I'm completely unable to do it... I can successfully login with basic permissions and everything works as expected, but I can't figure out how to request for extended permissions... When calling the Cocoon's FB login with the optional params, only the basic permissions are requested, so actually it seems that Cocoon (or FB) ignores the extended requests:

var socialService = CocoonJS.Social.Facebook.getSocialInterface();

socialService.login(function(loggedIn, error) {
    if (error) {
        console.error("login error: " + error.message);
    }else if (loggedIn){
    console.log("login suceeded");

    CocoonJS.Social.Facebook.getLoginStatus(function(response) {
    if (response.status === 'connected')
        CocoonJS.Social.Facebook.api("/me/permissions",
            function (response) {
                if (response && !response.error) {
                    console.log("Granted perms.: "+JSON.stringify(response));
                }else{
                    console.log("ERROR: unable to retrieve permissions");
                }
            }
        );
    }
    });
}, { 'scope': 'user_photos,publish_actions',return_scopes: true });

The thing is, the login function seems to work properly and the "login succeeded" log is printed, and so is the "Granted perms." log. However, it only shows the basic permissions, completely ignoring the 'user_photos' and the 'publish_actions' ones (they don't even appear in the retrieved list...

I tried calling the option with 'scope', with scope, with 'perms'... but nothing changes the result. I've asked in the CocoonJS forums, I've been googling for two weeks, tried different solutions, different Facebook accounts, even tried hardcoding the extended params in the CocoonJS's FB login function (which result in crash), but nothing works...

Anyone knows how to achieve it?

Thanks in advance for your time and effort!


Solution

  • CocoonJS parses the 'scope' parameter as a string with comma separated values. But these permission values are used with a readonly session login. Facebook has deprecated logging in with the "publish_actions" permission and suggests that an app should request the bare minimum of read permissions during login and then request any additional or publish permissions when a person actually needs them.

    I recommend that you request extended permissions this way:

    CocoonJS.Social.Facebook.requestAdditionalPermissions("publish", "publish_actions", function(response) {
      callback(response.error ? false : true);
    });