简体   繁体   中英

facebook mobile website (getUser(); always return 0)

I am trying to build up an Facebook application (website and mobile website). After buildup, I found that (ps I use the Facebook php API sdk),

index.php:

<!DOCTYPE html>
<?php
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
require_once('config/facebook.php');

config/facebook.php:

<?php
//Initializing
require 'facebook-php-sdk/src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
            'appId' => 'appId',
            'secret' => 'secret',
        ));
//End of Initializing
// Get User ID
$user = $facebook->getUser();
echo '<script>alert("' . $user . '");</script>';

PS I updated the latest version of facebook php api sdk

It work smoothly on website version (canvas web page). However in mobile, it always return 0.

Can anyone help me? Thanks.

There is no login handling logic here, so user will always be 0. You need to direct the user to login to your application

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

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