gpt4 book ai didi

javascript - facebook connect登录更麻烦(JS SDK)

转载 作者:行者123 更新时间:2023-11-30 18:37:40 25 4
gpt4 key购买 nike

我真的一点都不懂。我的目标是在我的主 aspx 文件中不要有一堆 js。我想要它在一个外部文件中。我根本无法让它发挥作用。

以下似乎 正常工作(获得登录弹出窗口),但它从不更新“访客”内容并且登录按钮保留在那里。控制台显示“FB 未定义”,所以显然它不知道 FB.api 意味着什么......抱歉,我对此很烂:|

[-----index.aspx----------------]

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" Inherits="MyGameEngineBeta.index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head runat="server">
<title>Scott's Test</title>
<script src="JS/jquery-1.6.4.min.js" type="text/javascript"></script>
</head>
<body>
<div id="fb-root"></div>
<script src="JS/facebook.js" type="text/javascript"></script>
<fb:login-button show-faces="false" width="200" max-rows="1"></fb:login-button>
<div>Welcome <span id="guest" class="UserNameWelcome">Guest</span><span id="name" class="UserNameWelcome"></span>!</div>
</body>
</html>

[-----facebook.js----------------]

window.fbAsyncInit = function () {
FB.init({
appId: 'mysiteid', // App ID
channelURL: '//www.mysite.net/channel.html', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
oauth: true, // enable OAuth 2.0
xfbml: true // parse XFBML
});

// Additional initialization code here
alert('Facebook initialized');
};

// 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));

//update guest/username if logged in or not
FB.api('/me', function (user) {
if (user != null) {
alert('logged in');
var name = document.getElementById('name');
name.innerHTML = user.name
$('#guest').hide();
} else {
alert('guest');
$('#image').hide();
$('#name').hide();
}
});

最佳答案

您在 window.fbAsyncInit 处理程序中调用了 FB.init,这很好,这样在加载所有 FB 内容之前不会执行。但是您在处理程序之外调用了 FB.api,这意味着您无法保证在调用 FB.api 之前 all.js 已完成加载。最简单的解决方案是在警报之后将 FB.api block 移动到 window.fbAsyncInit 函数中。

关于javascript - facebook connect登录更麻烦(JS SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7781775/

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