0
我正在實施我的fb應用程序,它連接到它自己的fb fanpage。我需要獲得像用戶名,ID等用戶信息,但當我點擊我的「Facebook身份驗證」鏈接,我最終會去一個空白的白頁? 您可以在這裏查看我的代碼:http://codepad.org/f0Tuh63vfacebook - 如何獲取用戶ID與phpsdk和js sdk
error_reporting(E_ALL);
ini_set('display_errors', true);
require 'facebook/facebook.php';
$facebook = new Facebook(array(
'appId' => '1',
'secret' => '2',
));
// See if there is a user from a cookie
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
print_r($user_profile);
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
}
}
else{
$loginUrl = $facebook->getLoginUrl(
array('scope' => 'user_about_me,user_birthday,email,publish_actions,offline_access,user_hometown,user_location',
'redirect_uri' => "https://domain.net/intro.php"
)
); // end of array
}
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($user) { ?>
Your user profile is
<pre>
<?php print htmlspecialchars(print_r($user_profile, true)) ?>
</pre>
<?php } else { ?>
<a href="<?php echo $loginUrl; ?>">Facebook authenticate</a>
<?php } ?>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true,
status: true
});
FB.Event.subscribe('auth.login', function(response) {
//window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
//window.location.reload();
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
這也是這裏http://codepad.org/f0Tuh63v 我在做什麼錯?
也有沒有辦法讓FB用戶ID不使用phpsdk或JS SDK?或者我必須使用這些插件?
好的。所以請在問題本身中提及,你已經正確地把appid和secret的值。或者使用像****這樣的東西,讓每個人都明白,只是通過看。 – gaurav 2013-02-20 21:41:15