[英]automatic Facebook Login like Hootsuite with Facebook JavaScript SDK
如何像Hootsuite一樣使用Facebook JavaScript SDK執行自動Facebook登錄?
使用我的代碼,我可以使用我的Facebook帳戶訪問我的Facebook應用程序,但是如何創建非Facebook登錄到我的網站,又如何通過該應用程序登錄到Facebook?
這是我的正常Facebook登錄代碼:
<div id="fb-root"></div>
<script>
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
document.getElementById('status').innerHTML = 'Verbunden';
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
window.fbAsyncInit = function() {
FB.init({
appId : 'AppID',
xfbml : true,
status : true,
cookie : true,
version : 'v2.1'
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/de_DE/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
應用程序登錄(這是hootsuite所使用的)意味着您必須首先登錄Facebook-因此沒有其他事情可做。 如果您在hootsuite上使用Facebook登錄名,則需要先登錄Facebook。
不必太擔心訪問令牌,JavaScript SDK通常會對此進行照顧,除非您想做更復雜的事情,例如生成擴展訪問令牌等等。
使用JavaScript SDK登錄非常容易: https : //developers.facebook.com/docs/reference/javascript/FB.login/v2.2
只需確保在用戶交互(鼠標單擊)時調用該函數-否則它可能會在瀏覽器中被阻止。
編輯:我看到如果有人在沒有Facebook登錄的情況下登錄您的網站,則您想使用Facebook自動登錄。 好吧,那是不可能的。 訪問令牌用於API調用,而不用於登錄。 如果用戶未在Facebook上登錄,則不能只是自動登錄。 但是您可以存儲訪問令牌以供以后使用,即使用戶未登錄,訪問令牌也仍然有效。關於如何使用訪問令牌以及哪些可用的令牌,請查看以下文章:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.