使用Facebook的API登录
问题描述:
我有像下面的代码。为什么$userId
总是0
?当我点击登录按钮时,我得到B.login() called when user is already connected.
。当我在fb中检查允许的应用程序时,会添加此应用程序。它看起来像我连接,所以它应该是我的id
,而不是0
。使用Facebook的API登录
<pre>
define('YOUR_APP_ID', ###);
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => ###,
'secret' => '###',
));
$userId = $facebook->getUser();
echo $userId;
?>
<html>
<body>
<?php if ($userId) {
$userInfo = $facebook->api('/' + $userId); ?>
Welcome <?= $userInfo['name'] ?>
<?php } else { ?>
<div id="fb-root"></div>
<fb:login-button></fb:login-button>
<?php } ?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<? echo('####'); ?>',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</body>
</html>
答
我有当我用FBJS SDK的连接还我担心自己是如何运行的功能,以及如何这个问题解决了,但不严重取得成功的同样的问题...
我是指你这个链接https://github.com/facebook/php-sdk,因为它易于使用,为Facebook的连接....
此外,我不希望在这里,因为它太冗长复制我的代码和属于笨
答
你在使用IE吗?如果是这样,您需要将P3P标题发送到您的所有页面。
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
如果没有,请在登录到应用程序时给予用户良好的权利。
只是主代码算法的一小段代码会很有用 – 2012-04-28 20:53:55