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