我正在尝试迁移到新的Facebook API网站,并且无法使其顺利运行。我想一起使用Javascript和PHP SDK,但遇到问题。我可以进行身份验证,但该页面不会自动刷新。Facebook Oauth 2.0使用PHP 3.1.1和Javascript SDK登录
我已经搜遍整个SO和Facebook的文档,但仍然无法得到这个正常工作。我已阅读http://developers.facebook.com/blog/post/534/,下载了最新的PHP SDK(3.1.1),并基本上从Facebook上复制了上述帖子中的示例。我已经在我的应用“迁移”设置中做出了我认为是正确的设置,但这可能是问题所在。我不能张贴图片,所以这里的设置:
- 删除已过时的API:启用
- 部队使用的登录秘密:启用
- 加密访问令牌:启用
- 增强验证对话框:启用
- (一切是禁用)
下面是代码:
<?php
require 'php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// 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');
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
}
}
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($user_profile) { ?>
Your user profile is
<pre>
<?php print htmlspecialchars(print_r($user_profile, true)) ?>
</pre>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: 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://developers.facebook.com/blog/post/534/?fb_comment_id=fbc_10150280812027726_18008036_10150281567792726)。 – ifaour