2012-09-17 19 views
0

我有fblogin到我的網站。我想將ID,姓名和電子郵件保存到數據庫。所以PLease告訴我如何將這些值從 腳本傳遞給服務器。由於沒有太多的經驗,我不知道如何將值從腳本傳遞到服務器。如果其可能的 從腳本ta服務器傳遞值。請告訴我解決方案。如何將Facebook用戶的信息值從腳本傳遞並保存到服務器?

下面我貼我的完整編碼

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
<title>Facebook Get Logged in User Details UserName,Email,Profile Image</title> 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
</head> 
<body> 
<script type="text/javascript"> 
// 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)); 

// Init the SDK upon load 
window.fbAsyncInit = function() { 
FB.init({ 
appId: 'XXXXX', // App ID 
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File 
status: true, // check login status 
cookie: true, // enable cookies to allow the server to access the session 
xfbml: true // parse XFBML 
}); 

// listen for and handle auth.statusChange events 
FB.Event.subscribe('auth.statusChange', function(response) { 
if (response.authResponse) { 
// user has auth'd your app and is logged into Facebook 
//var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture"; 
var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/education "; 
var uuu = "http://graph.facebook.com/me?education=" + response.authResponse.accessToken 
FB.api('/me', function(me) {alert(me.first_name) 
var Name = me.name; 
var Email = me.email 


}) 

document.getElementById('auth-loggedout').style.display = 'none'; 
document.getElementById('auth-loggedin').style.display = 'block'; 
} else { 
// user has not auth'd your app, or is not logged into Facebook 
document.getElementById('auth-loggedout').style.display = 'block'; 
document.getElementById('auth-loggedin').style.display = 'none'; 
} 
}); 
$("#auth-logoutlink").click(function() { FB.logout(function() { window.location.reload(); }); }); 
} 
</script> 
<form id="form1" runat="server"> 
<h1> 
    &nbsp;Facebook Login Authentication </h1> 
<div id="auth-status"> 
<div id="auth-loggedout"> 
<div class="fb-login-button" autologoutlink="true" scope=" user_checkins,user_website, user_relationship_details, user_hometown, user_religion_politics, user_education_history, user_about_me, user_birthday, user_status, publish_stream, user_photos, read_stream, friends_likes">Login with Facebook</div> 
</div> 



<div id="auth-loggedin" style="display: none"> 
    <br /> 
    Name:<b><span id="auth-displayname"></span></b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;(<a href="#" id="auth-logoutlink">logout</a>)<br /> 
First Name: <b><span id="firstname"></span></b><br /> 

Last Name: <b><span id="lastname"></span></b><br /> 

Email: <b><span id="Email"></span></b><br /> 

gender: <b><span id="gender"></span></b><br /> 

Dob of birth: <b><span id="birth"></span></b><br /> 

Location: <b><span id="location"></span></b><br /> 

</div> 

    </div> 
</form> 
</body> 
</html> 
+0

將值從客戶端傳輸到服務器的可能方法是f.e. AJAX或HTML表單......取決於您。 – CBroe

+0

@CBroe:如何使用Ajax傳遞價值 – Sham

+0

SO不是教這種基礎知識的地方。請在網上搜索教程或其他內容。 – CBroe

回答

0

我已經爲衝浪最後2天上網,發現soultion上我自己將客戶端的價值傳遞給服務器。下面我有 粘貼解決方案...

<script type="text/javascript"> 

var data2Send = '{"fbid":"222222", "fbemail":"[email protected]", "fbsex":"Male", "fbdob":"22/03/1989"}'; 
$.ajax({ 
    type: "POST", 
    url: 'passvaluw.aspx/Testmethod', 
    data: data2Send, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    success: function (arg) {console.log(arg) //call successfull 
    $("#lbltxt").text(arg.d);}, 
    error: function (xhr) { 
     //error occurred 
    } 
}); 

</script> 


[System.Web.Services.WebMethod] 
    public static string TestMethod(string fbid, string fbemail, string fbsex, string fbdob) 
    { 

return fbemail; 

} 
1

如果你想保存在服務器中的用戶信息,那麼你就需要使用一些服務器端語言.. 假設你使用PHP,然後在情況下,就需要用戶信息傳遞給服務器,並首先檢查用戶信息是否存在於你的數據庫或不..

//連接與您的數據庫//請求用戶信息//查詢來獲取用戶 信息從db

如果(你在數據庫中的用戶信息){//顯示用戶配置文件} 其他{// 上傳到數據庫}

相關問題