这是我的代码:
<?php
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => '',
'secret' => ''
));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Facebook PHP</title>
</hea <body>
<h1>Hello World</h1>
<?php
//get user from facebook object
$user = $facebook->getUser();
if ($user): //check for existing user id
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>';
echo '<p>getType: ',$e->getType(), '</p>';;
echo '<p>getMessage: ',$e->getMessage(), '</p>';;
}
echo '<p>User ID: ', $user, '</p>';
//print logout link
echo '<p><a href="logout.php">logout</a></p>';
else: //user doesn't exist
$loginUrl = $facebook->getLoginUrl(array(
'diplay'=>'popup',
'scope'=>'email',
'redirect_uri' => 'http://apps.facebook.com/blabla'
));
echo '<p><a href="', $loginUrl, '" target="_top">login</a></p>';
endif; //check for user id
?>
</body>
</html>
答案 0 :(得分:0)
只需进行一些修改即可解决,我GUESS(猜猜看,因为我还没看到facebook.php)
<?php
require 'facebook.php';
$facebook = new Facebook(array('appId' => '', 'secret' => ''));
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Facebook PHP</title>
</head>
<body>
<h1>Hello World</h1>
<?php
//get user from facebook object
$user = $facebook->getUser();
if ($user): //check for existing user id
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>';
echo '<p>getType: ',$e->getType(), '</p>';;
echo '<p>getMessage: ',$e->getMessage(), '</p>';;
}
echo '<p>User ID: ', $user, '</p>';
//print logout link
echo '<p><a href="logout.php">logout</a></p>';
else: //user doesn't exist
$loginUrl = $facebook->getLoginUrl(array(
'diplay'=>'popup',
'scope'=>'email',
'redirect_uri' => 'http://apps.facebook.com/blabla'
));
echo '<p><a href="', $loginUrl, '" target="_top">login</a></p>';
endif; //check for user id
?>
</body>
</html>
让我们看看会发生什么,我们在这里调整,保持联系。