请求权限弹出窗口后,facebook 应用程序不会重新加载 - 使用 PHP SDK (v.3.1.1)
正如所指出的,我的旧 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>
My old facebook application requires updating to the latest php sdk as was pointed out
in another question. My next problem is getting it to work with the latest php sdk 3.1.1
I'm using the example that comes with the latest php sdk ie; with_js_sdk.php
It works fine up until one gives permission to access the application but instead of reloading bringing the user
to the application it returns the user to the log in again. How do I get the user redirected to the application
component. Note I have an alert that it calls window.location.reload(); but it doesn't show the user after
he added the application
The code is below:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个简单的解决方案,无需使用 facebook 上的 sdk。
链接是:
https://developers.facebook.com/docs/appsonfacebook/tutorial/
做了诡计。
大卫·J。
I found a simple solution without using the sdk which was on facebook.
the link is:
https://developers.facebook.com/docs/appsonfacebook/tutorial/
did the trick.
David j.