我正在尝试在我的网站上添加 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>';
}
任何想法 ?