[英]Facebook implementation, after registration
當用戶想要注冊到我的網站時,我正在使用以下腳本,因此當他批准該應用程序時,字段將自動填寫,而他只需要提交表單即可。
但是我被困在登錄機制的第二部分,如何檢查用戶是否已經登錄到他的facebook帳戶並且他批准了我的申請?
我將每個用戶的facebook ID保留在我的用戶數據庫中。
注意:我使用的是用戶流程,而不是服務器流程。
<script type="text/javascript">
var appId = "xxxxxxxxx";
if(window.location.hash.length == 0)
{
url = "https://www.facebook.com/dialog/oauth?client_id=" +
appId + "&redirect_uri=" + window.location +
"&response_type=token";
//window.open(url);
} else {
accessToken = window.location.hash.substring(1);
graphUrl = "https://graph.facebook.com/me?" + accessToken +
"&callback=displayUser"
//use JSON-P to call the graph
var script = document.createElement("script");
script.src = graphUrl;
document.body.appendChild(script);
}
function displayUser(user) {
myform = document.forms['regform'];
username = user.name;
first = username.split(" ");
myform.elements['fname'].value = first[0];
myform.elements['lname'].value = first[1];
myform.elements['username'].value = first[0]+first[1];
myform.elements['email'].value = user.email;
myform.elements['fbid'].value = user.id;
}
</script>
您可能要使用Facebook JS SDK: http : //developers.facebook.com/docs/reference/javascript/
例如,要檢查登錄狀態,您可以執行以下操作:
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
} else {
// no user session available, someone you dont know
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.