tlo*_*lin 5 javascript asp.net ajax facebook
我正在尝试实施Facebook Connect单点登录网站.我最初只有一个Connect按钮(<fb:login-button>),用户每次想要登录时都必须点击.我现在有自动登录和注销功能.也就是说,我的网站将检测登录的Facebook帐户,如果它可以找到我的网站的一个用户帐户匹配,则自动验证它们,如果Facebook会话丢失,则自动取消验证.我还有一个手动注销按钮,可以将用户从我的网站和Facebook中注销.所有这些都正常工作,但现在我的原始Connect按钮间歇性地无法正确呈现.它只是显示为普通的XHTML(即,它看起来像纯文本 - 不是按钮 - 并且是不可点击的),并且没有应用XFBML.这是基本代码:
在每个页面上:
<body>
{...}
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript>
FB.init('APIKey', '/xd_receiver.htm');
var isAuth; // isAuth determines if the user is authenticated on my site
// it should be true on the logout page, false on the login page
FB.ensureInit(function(){
var session = FB.Facebook.apiClient.get_session();
if (session && !isAuth) {
PageMethods.FacebookLogin(session.uid, session.session_key, FBLogin, FBLoginFail);
// This is an AJAX call that authenticates the user on my site.
} else if(!session && isFBAuth) {
PageMethods.FacebookLogout(FBLogout, FBLogoutFail);
// This is an AJAX call that deauthenticates the user on my site.
}
// the callback functions do nothing at the moment
});
</script>
{...}
</body>
Run Code Online (Sandbox Code Playgroud)
在登录页面上:(登录用户看不到此页面)
<body>
{...}
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript>
FB.init('APIKey', '/xd_receiver.htm');
{...} // auto-auth code as on every page
</script>
<!-- This is the button that fails to render -->
<fb:login-button v="2" onlogin="UserSignedIntoFB();" size="large" autologoutlink="true"><fb:intl>Login With Your Facebook Account</fb:intl></fb:login-button>
<script type="text/javascript">
function UserSignedIntoFB() {
{...} // posts back to the server which authenticates the user on my site & redirects
}
</script>
{...}
</body>
Run Code Online (Sandbox Code Playgroud)
在注销页面上:(此页面对于已注销的用户不可见)
<body>
{...}
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
<script type="text/javascript>
FB.init('APIKey', '/xd_receiver.htm');
{...} // auto-auth code as on every page
</script>
<script type="text/javascript">
function FBLoggedOut() {
{...} // posts back to the server which deauthenticates the user on my site & redirects to login
}
function Logout() {
if (FB.Facebook.apiClient.get_session()) {
FB.Connect.logout(FBLoggedOut); // logs out of Facebook if it's a Facebook account
return false;
} else {
return true; // posts back if it's a non-Facebook account & redirects to login
}
}
</script>
<a onclick="return Logout();" href="postback_url">Sign Out</a>
{...}
</body>
Run Code Online (Sandbox Code Playgroud)
我已经看过的一些事情:
我怀疑在注销时我需要做的其他事情(比如清除会话或cookie),但根据我读过的关于Facebook Connect的所有内容,我需要做的就是调用注销功能(并取消对我的认证)服务器端).我真的很茫然; 有没有人有任何想法可能是错的?
小智 6
确保在页面的非常结束处调用facebook js include(FeatureLoader),这样你的页面呈现然后facebook JS在将文本转换为按钮之后做了一些魔术.否则,这是在调用fb的服务器和在浏览器中加载你的网站内容之间的竞赛......
至少那是我遇到的问题.
| 归档时间: |
|
| 查看次数: |
8536 次 |
| 最近记录: |