gpt4 book ai didi

javascript - Facebook javascript SDK FB.login 在 Facebook iFrame 中不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 04:29:15 33 4
gpt4 key购买 nike

我们正在使用 Facebook JavaScript SDK 来验证我们的 Facebook 应用程序。该应用程序的 Canvas URL 配置为 http://facebook.elgifto.com/Home/Index/ .以下是我们用来对 Facebook 用户进行身份验证的代码。

    <script type="text/javascript">
window.fbAsyncInit = function() {
debugger;
FB.init({
appId: '<%= ViewData["AppId"].ToString() %>', // App ID
channelUrl: '<%= ViewData["ChannelUrl"].ToString() %>', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
oauth: true
});

FB.Event.subscribe('auth.login', function(response) {
if (response.status === 'connected') {
// the user is logged in and connected to your
// app, and response.authResponse supplies
// the user’s ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
startApp(uid, accessToken);
}

});

};

// Load the SDK Asynchronously
(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));




function startApp(uid, accessToken) {
var baseUrl = '<%= ViewData["AppBaseURL"].ToString() %>';
var redirectUrl = baseUrl + '?uid=' + uid + '&accessToken=' + accessToken;
window.top.location.href = redirectUrl;
//document.location = redirectUrl;
}
</script>
<fb:login-button onlogin="initiateLogin()" perms="email,user_about_me,user_birthday,friends_about_me,friends_birthday">Login with Facebook</fb:login-button>

当访问为 http://apps.facebook.com/giftguru 时,以上代码在 Facebook 中不起作用。 .但是我们可以通过 http://facebook.elgifto.com/Home/Index 访问它

最佳答案

此问题与浏览器阻止弹出窗口有关。 (在 Facebook 之外为你工作的事实可能是因为你以前有时被允许这样做,对我来说它被阻止以及在应用程序内)。

在没有用户交互(如元素 click 或表单 submit)的情况下,您永远不应该调用 FB.login 以确保浏览器不会阻塞登录窗口。

更新:
你在这里混合了很多东西:

  1. http://facebook.elgifto.com/Home/Index 上的页面正在使用 Application #316853928368079 (此应用程序没有命名空间!)
  2. 您的 OAuth 对话框 URL 在 client_id 周围有 '(撇号),这是错误的!
  3. OAuth Dialog 不工作(可能也是由于应用程序设置,应用程序域?)
  4. 位于 http://apps.facebook.com/giftguru 的应用程序是 Application #83808922524并且有错误的 Canvas URL! 证明:
    Facebook App Canvas wrapper

关于javascript - Facebook javascript SDK FB.login 在 Facebook iFrame 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9820362/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com