0

私は自分のサイトにfbloginを持っています。ID、名前、メールアドレスをデータベースに保存したい。したがって、PLeaseは、これらの値をスクリプトからサーバーに渡す方法を教えてください。私はあまり経験がないので、スクリプトからサーバーに値を渡す方法がわかりません。スクリプト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(you have user info in database){ //ユーザー プロフィールを表示する } 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 に答える