我正在按如下所示進行Facebook登錄。但事件不會觸發(FB.Event.subscribe(..),GetFBLoginStatus())。我在本地主機上運行它,並在我的應用程序中指定它,但爲此目的沒有必要。它看起來像JavaScript沒有加載,但facebookbutton呈現。我必須改變什麼?彈出窗口要求權限,當我點擊「登錄」,但沒有更多。Loading Facebook javascript
<html>
<head>
<title>My Facebook Login Page</title>
</head>
<body>
<div id="fb-root"></div>
<script type ="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: 'some id', // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.Event.subscribe('auth.login', function (response) { alert('You logged in'); });
};
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
function GetFBLoginStatus() {
FB.getLoginStatus(function (response) {
console.log(response);
if (response.status === 'connected') {
var accessToken = response.authResponse.accessToken;
alert(accessToken);
} else if (response.status === 'not_authorized') {
//login function
alert('login first');
} else {
//login function
alert('login first');
}
}, true);
}
</script>
<div class="fb-login-button" scope="email,user_checkins,read_mailbox">Login with Facebook</div>
//this function is not work -> javascript not loaded?
<button onclick = "GetFBLoginStatus();">GetStatus</button>
</body>
感謝您的有用評論,Victor.Also我建議開發人員這個http://facebookhelper.codeplex.com/ – 2012-08-06 10:05:07
在mvc中使用此包添加參考webmatrix.data && webmatrix.webdata並在屬性中設置鎖定'真正' – 2012-08-06 14:15:14