我使用以下代码获取用户的Facebook详细信息。现在,当我运行它时,页面会显示“请登录”,其中login是锚标记。当我点击登录时,另一页显示“无效的应用程序ID:YOUR_APP_ID”。当我做这一切时,我已登录到Facebook。那么为什么我没有得到细节?
<?php
include 'facebook-php-sdk/src/facebook.php';
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'allowSignedRequest' => false // optional but should be set to false for non-canvas
apps
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?php
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 {
// No user, print a link for the user to login
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
</body>
</html>
答案 0 :(得分:2)
我认为您需要将YOUR_APP_ID和YOUR_APP_SECRET替换为您在创建应用后在Facebook开发者页面上找到的值。
Where can I find my Facebook application id and secret key?
阅读第一个问题,然后点击“此处”链接。