mercredi 28 octobre 2015

Facebook PHP SDK/Laravel 5: Check if a user has granted a certain set of permissions

I want to check that a user has authorized the following permissions; 'manage_pages', 'publish_pages', 'read_insights', for my app. In short, if they decline one or more permissions, I need to know, as all are required.

Here's my callback method once I get the user's access token. How do I verify they approved all permission requests?

Note: I'm using the SammyK Laravel Facebook SDK package.

public function handleFacebookCallback()
    {
        try {
            $token = Facebook::getAccessTokenFromRedirect();

            $user = Facebook::get('/me?fields=permissions', $token)->getGraphUser();
            $permissions = $user['permissions']->asArray();

            // permissions: 'manage_pages', 'publish_pages', 'read_insights'

            if (array_key_exists('publish', $permissions['data'][0]))
            {
                // permissions exist, proceed
            }
            else 
            {
                // user denied permission(s), redirect
            }
        }
        ....



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/20bjdxS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire