我的旧facebook应用程序需要更新到最新的php sdk,正如所指出的那样 在另一个问题。我的下一个问题是使用最新的php sdk 3.1.1
我正在使用最新的php sdk附带的示例ie; with_js_sdk.php
它可以正常工作,直到一个人允许访问应用程序,而不是重新加载用户 到应用程序,它将用户再次返回到登录。如何让用户重定向到应用程序 零件。注意我有一个警告,它调用window.location.reload();但它没有显示用户 他添加了申请
代码如下:
<?php
require 'facebook.php';
$appCanvasPage = 'https://apps.facebook.com/myapp/';
$app_id = "";
$app_secret = "";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $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;
}
}
echo "user=".$user."\n";
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($user) { ?>
<h2> THIS IS MY APP </h2>
<?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) {
alert(At reload);
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>
答案 0 :(得分:1)
我发现了一个简单的解决方案,而没有使用Facebook上的sdk。
链接是: https://developers.facebook.com/docs/appsonfacebook/tutorial/
<?php
$app_id = "YOUR_APP_ID";
$canvas_page = "YOUR_CANVAS_PAGE_URL";
$auth_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
做了这个伎俩。
David j。