0

我有 fblogin 到我的网站。我想将 ID、姓名和电子邮件保存到数据库。所以请告诉我如何将这些值从脚本传递到服务器。由于我没有太多经验,我不知道如何将值从脚本传递到服务器。如果可以从脚本 ta 服务器传递值。请告诉我解决方案。

下面我发布了我的完整编码

<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>
4

2 回答 2

1

如果要将用户信息保存在服务器中,那么您需要使用一些服务器端语言。假设您使用PHP,那么在这种情况下,您需要将用户信息传递给服务器并首先检查用户信息是否存在于你的分贝与否..

//连接你的数据库 //请求用户信息 //查询从数据库获取用户信息

if(你在数据库中有用户信息){ //显示用户资料 } else{ //上传到你的数据库 }

于 2012-09-17T10:27:55.037 回答
0

我在过去 2 天上网,发现自己的灵魂将价值从客户端传递到服务器。下面我已经粘贴了解决方案......

<script type="text/javascript">

var data2Send = '{"fbid":"222222", "fbemail":"aaa@dsf.com", "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;

}
于 2012-09-21T09:35:20.043 回答