简体   繁体   中英

Facebook SDK-PHP : getting the uid of the connected user

I'm trying to get the UID of the connected user with Facebook SDK for PHP, but it doesn't work, and all other things work properly; it means that the problem is not in the connection to the application.

I tried this code but it is always returning 0 while I'm connected to Facebook; I even tried with other accounts but no solution.

$uid = $facebook->getUser(); 
$facebook = facebook_get();
    $uid = $facebook->getUser();
    echo $uid;

and here's facebook_get()

function facebook_get()
{
    include('lib/fbapi/facebook.php');
    $config = array();
    $config['appId'] = '...';
    $config['secret'] = '...';
    $facebook = new Facebook($config);
    return $facebook;
}

Can you post your authentication code you've coded or you're using? If you post, we can look into your code and give you the answer to why it's returning 0, it could be your authentication code which is not coded properly or it could be config error.etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM