0

Web サイトに Facebook PHP SDK を追加しようとしていますが、誰も Facebook に接続していない場合、getLoginUrl() で間違った URL が表示されます (内部サーバー エラー)。

彼は私のコードです:

include("facebook/src/facebook.php");
$config = array();
$config['appId'] = 'myAppId';
$config['secret'] = 'mySecretKey';
$facebook = new Facebook($config);
$user_id = $facebook->getUser();

if($user_id)
{
    // We have a user ID, so probably a logged in user.
    // If not, we'll get an exception, which we handle below.
    try
    {
        $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];
    }
    catch(FacebookApiException $e)
    {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
    }   
}
else // The problem is below \\
{       
    // No user, print a link for the user to login
    $login_url = $facebook->getLoginUrl(array('scope' => 'email,publish_stream,user_location,user_birthday'));
    echo 'Please <a href="' . $login_url . '">login.</a>';
}

何か案が ?

4

0 に答える 0