構建自己的Facebook - 登錄按鈕,使用下面的代碼登錄功能:
<div class="fb-login-button" data-scope="email" onclick="fbStatus();">Connect</div>
<script>
function fbInit() {
window.fbAsyncInit = function() {
FB.init({
appId: 'XXXXX',
status: false,
cookie: true,
xfbml: true
});
//auth.statusChange
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status.indexOf('connected') != -1) {
// the user is logged in and has authenticated 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;
//Handle the access token
});
} else if (response.status.indexOf('not_authorized') != -1) {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
};
(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 fbStatus() {
//auth.statusChange
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status.indexOf('connected') != -1) {
// the user is logged in and has authenticated 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;
//Handle the access token
});
} else if (response.status.indexOf('not_authorized') != -1) {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated 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;
//Handle the access token
});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
}
</script>
我已經創建了一個應用程序,並實施了標準按鈕,但我認爲有一些方法來定製它 - 我已經看到了我的例子很多那個按鈕,認爲有可能成爲它的官方版本,但我可能是錯的。 – DonMB
請提供您的代碼更詳細的解決方案,小提琴將盡最大努力.. :)如果其按鈕的大小具體然後請更具體的要求。 – MarmiK
我通過https://developers.facebook.com/docs/reference/plugins/login/創建它 那不是問題。問題是按鈕的佈局。它看起來不是我希望它看起來如何。但我想這是官方的,並且沒有可能改變它。 – DonMB