2

カスタム フィールドで動作する登録フォームを取得し、リダイレクト ページの Cookie を介してカスタム フィールドを取得できます。私が理解できないのは、次のページで Facebook 情報 (名前、電子メール、誕生日) を取得する方法です (私は PHP の専門家ではありません)。「データの読み取り」セクション( FB Documentation )のドキュメントを何度か読み、インターネットを精査しましたが、PHPとC#のソリューションしか見つかりません。

誰かが私を助けてくれるなら、javascript、jQuery、または ColdFusion ソリューションを探しています。

以下は、クイックリファレンスとしての私のコードです。現状では、ページ 2 は Cookie 情報をダンプするだけです。

ページ1

<html>
<head>
  <title>My Facebook Login Page</title>
</head>
<body>

<!--- Facebook Call --->
  <div id="fb-root"></div>
  <script>
    window.fbAsyncInit = function() {
      FB.init({
        appId      : 'myAppID', // App ID
        channelUrl : 'http://.../channel.html', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
      });
    };
    // 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));
  </script>

<!--- Output Facebook Box---> 
<fb:registration redirect-uri="http://.../page2.cfm" 
    fields='[
        {"name":"name"},
        {"name":"email"},
        {"name":"displayName","description":"Display Name:", "type":"text"},
        {"name":"location"},
        {"name":"birthday"}
        ]'
    onvalidate="validateAndSave">
</fb:registration>

<!---Validation + set Cookie --->
<script>
     function validateAndSave(form) {
          if (!form.displayName) {
            return({"displayName":"Display Name is Required"});
          }
              document.cookie = 'fbInfo='+'displayName='+form.displayName;
              return {};
        }
</script>
</body>

4

1 に答える 1

0

これは、FB JavaScript API を使用した試行錯誤に基づく私の実装です。

function checkFB()
{   
    if (typeof(FB) === "undefined")
    {
        var t = setTimeout("checkFB()", 1000);
        if (debug) console.log("FB is still undefined, try again in 1 second.");
    }
    else
    {
        if (debug) console.log("FB is defined, try to login -> ");

        //Function to check the current login status of facebook            
        FB.getLoginStatus(function(r)
        {
            if (r.status === "not_authorized")
            {
                if (debug) console.log("-> NOT AUTHORIZED ");
            }
            else if (r.status === "connected")
            {
                if (debug) console.log("-> connected ");

                if (r.authResponse) 
                {
                    FB.api('/me', function(rr) {
                        document.getElementById("fbFname").value = rr.first_name;
                        document.getElementById("fbLname").value = rr.last_name;
                        document.getElementById("fbEmail").value = rr.email;
                        document.getElementById("fbID").value = rr.id;
                        document.getElementById("status").value = "OK";
                    });

                    submitFB();
                } 
                else 
                {
                    document.getElementById("status").value = "NOT AUTHORIZED";
                    history.go(-1);
                    if (debug) console.log("NOT AUTHORIZED");
                }
            }
            else
            {
                if (debug) console.log("-> not connected -> POP UP BOX expected ");
                // start login process
                FB.login(function(re) 
                {
                    if (re.authResponse) 
                    {
                        FB.api('/me', function(rr) {
                            document.getElementById("fbFname").value = rr.first_name;
                            document.getElementById("fbLname").value = rr.last_name;
                            document.getElementById("fbEmail").value = rr.email;
                            document.getElementById("fbID").value = rr.id;
                            document.getElementById("status").value = "OK";
                        });
                        submitFB();
                    } 
                    else 
                    {
                        document.getElementById("status").value = "NOT AUTHORIZED";
                        history.go(-1);
                        if (debug) console.log("NOT AUTHORIZED");
                    }
                }, 
                {scope: 'email'}); // we define what information we want to get from the user
            }
        });
    }
}

facebook から appID を取得済みで、チャンネル ファイルがあることを願っています。'myAppID' と 'http://.../channel.html' を置き換える必要があります。

 FB.init({
        appId      : 'myAppID', // App ID
        channelUrl : 'http://.../channel.html', // Channel File
于 2012-10-24T08:40:17.793 に答える