Domanda

I am creating a website using ASP.net MVC 4 and I can have the users log in with their facebook account, the problem is that if a user denies publish permission I want to check their active permission and a way to re-prompt in case its necessary, I have created this script:

<script>

    document.getElementById('checkPerms').onclick = function () {
        checkPermissions();
    };


    var checkPermissions = function () {
        FB.api('/me/permissions', function (response) {
            console.log(response);
        });
    };


</script>

It should return the active permissions but I get an error: An active access token must be used to query information about the current user.

so I cant check for the user's permission and I am also not sure how to redirect to an action or how to re-prompt for those permissions.

È stato utile?

Soluzione 2

I've found the solution, I had to save the Facebook token and then retrieve it from a view model.

FB.init({
            appId: APPID,
            authResponse: {
                accessToken: '@Model.FacebookToken'
            }
        });

after this, I had to check if the permission existed; if not, then I request them again like this:

 var checkPermissions = function () {
        FB.api('/me/permissions', function (response) {
            var perms = response.data[0];
            // Check for publish_stream permission
            if (perms.publish_stream) {
                console.log('User has permission')
            } else {
                FB.login(function (response) {
                    // Request permission
                }, { scope: 'publish_actions' });
            }

        });
    };

Altri suggerimenti

This error:

An active access token must be used to query information about the current user

simply means that there is no user in session currently. So, /me will fail. You have not mentioned so I'm not sure where exactly you are checking the permissions. But you should check them at that point when a user is in session.

/me/permissions is normally used for checking the the publishing permissions, because people skip the this permission many often. So, just before posting you call this and ask for the publishing permission.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top