Facebook getLoginUrl and next parameter doesn't work properly

前端 未结 2 1704
猫巷女王i
猫巷女王i 2021-01-15 00:15

My Code:

$url = $fb->getLoginUrl(array(\'scope\'=>\'email\',\'next\'=>\'http://apps.facebook.com/APPID/\'));
echo \"

        
相关标签:
2条回答
  • 2021-01-15 00:31

    Change the redirect uri in the app settings page.

    0 讨论(0)
  • 2021-01-15 00:48

    You have to change this URL to redirect you app where you want after authentication.

    You have to change this URL to redirect you app where you want after authentication.

    OR You can Do this

    First of all, you don't have to edit PHP SDK, below is the sample for authenticating the user and then redirecting to your landing page,

    Make sure you replace:

    YOUR-APP-ID-HERE with Your facebook application id,

    YOUR-APP-API-SECRET-HERE with Your facebook application secret key

    YOUR-REDIRECT-URL-HERE with Your landing page URL

    <?php
    
        // Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/
        require ('facebook.php');
    
        define('FACEBOOK_APP_ID',"YOUR-APP-ID-HERE");
        define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET-HERE");
        define('REDIRECT_URI',"YOUR-REDIRECT-URL-HERE");
        $user = null;
    
        $facebook = new Facebook(array(
            'appId' => FACEBOOK_APP_ID,
            'secret' => FACEBOOK_SECRET,
            'cookie' => true
        ));
    
        $user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.
    
        if($user == 0) {
            // If the user is not connected to your application, redirect the user to authentication page
            /**
             * Get a Login URL for use with redirects. By default, full page redirect is
             * assumed. If you are using the generated URL with a window.open() call in
             * JavaScript, you can pass in display=popup as part of the $params.
             * 
             * The parameters:
             * - redirect_uri: the url to go to after a successful login
             * - scope: comma separated list of requested extended perms
             */
    
            $login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI));
    
            echo ("<script> top.location.href='".$login_url."'</script>");
    
        } else {
            // if the user is already connected, then redirect them to landing page or show some content
            echo ("<script> window.location.href='".REDIRECT_URI."'</script>");
        }
    
    ?>
    

    If you want to get extended permissions, then simply add another "scope" parameter to the login url, ex:

    $login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI,'scope' => 'comma-separated-list-of-requested-extended-perms'));
    
    0 讨论(0)
提交回复
热议问题