Facebook API有时无法加载

时间:2012-06-04 14:57:06

标签: facebook facebook-graph-api

使用

时遇到问题
 $facebook->api('/me','GET');

首次加载页面时,没有任何反应。我必须重新加载页面才能使脚本正常工作。不确定问题出在哪里。

require_once('src/facebook.php');

$app_id = "APP_ID";
$app_secret = "APP_SECRET";

// Init facebook api.
$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true,
));

//Facebook Authentication part
$user_id = $facebook->getUser();
    $loginUrl   = $facebook->getLoginUrl(
        array(
            'scope'         => 'publish_stream, user_likes'
        )
);

if (!$user_id) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}

$user_profile = $facebook->api('/me','GET');
$user_gender = $user_profile['gender'];
    if($user_gender == 'male'){
        echo "you are male";
    } else {
        if ($user_gender == 'female'){
            echo "you are female";
        } else{
            echo "gender not specified";
        }
    }

我尝试了$ facebook-&gt; api('/ me','GET'); out和echo $ user_id,例如,它可以工作。

0 个答案:

没有答案