0

js sdk を使用して、名前、場所、ID などの基本情報を取得しています。素晴らしいですが、もう 1 つだけ必要なことがあります。それはメールです。ここで、電子メールには拡張アクセス許可が必要であることを読みました。また、ここでfb.login を使用して拡張パーマを要求する方法も読みました。

このチュートリアルのコードでは、fb.loginを呼び出しませんが、訪問者はログインしてアプリのアクセス許可を付与するように求められます (そうでない場合)。それはどのように行われますか?登録ボタン (チュートリアルから少し変更) は、スタイルを設定するクラスを持つ div です。

<div class="fb-login-button" data-show-faces="false" data-width="400" data-max-rows="1">Register</div>

さて、「登録」ボタンを調べたところ、非常に変換されたレンダリングが見つかりましたが、ボタンイベントをクリックしたユーザーがどのように処理されるかについて、onclickや手がかりが見つかりませんでした。私の推測では、スタイリングからの iframe には src があり、イベントは fb 側にある必要があります。

スクリプトに戻ると、おそらく fb.login は fb.init にあり、そこにパーマ リクエストを追加できると思いましたが、fb.login はありませんか?? 下のelseブランチに入れようかと思ったのですが、今は何もなく、動作します...メールの拡張パーマを差し引いて?

window.fbAsyncInit = function ()
            {
                FB.init({...removed for concise....});

                //If user authorizes using fb account info:
                FB.Event.subscribe('auth.authResponseChange', function (response)
                {
                    if (response.status === 'connected') 
                    {
                        ...removed for concise code...
                    } 
                    else if (response.status === 'not_authorized') 
                    {
                        // the user is logged in to Facebook, 
                        // but has not authenticated your app
                    } 
                    else 
                    {
                        // the user isn't logged in to Facebook.
                        //**HERE IS WHERE I WOULD HAVE THOUGHT TO PUT FB.Login**
                    }
                });


            };

ですから、パズルのピースがどのように組み合わされるのか、私にはわからないのです。json にメールを含めるには拡張アクセス許可を要求する必要があることはわかっていますが、パーマを作成する場所がわかりません。でリクエスト???

このコードはページ内の実際のコードであるため、SDK の実装全体を確認できます。

<div id="fb-root"></div>
        <script>
            window.fbAsyncInit = function ()
            {
                FB.init({
                    appId: 12324, // App ID
                    status: true, // check login status
                    cookie: true, // enable cookies
                    xfbml: true  // parse XFBML
                });

                //If user authorizes using fb account info:
                FB.Event.subscribe('auth.authResponseChange', function (response)
                {
                    if (response.status === 'connected') {
                        // the user is logged in and has authenticated your
                        // app, and response.authResponse supplies
                        // the user's ID, a valid access token, a signed
                        // request, and the time the access token 
                        // and signed request each expire
                        var uid = response.authResponse.userID;
                        var accessToken = response.authResponse.accessToken;

                        // send access token to server so we can fill in fields
                        var form = document.createElement("form");
                        form.setAttribute("method", 'post');
                        form.setAttribute("action", '/mypage');

                        var field = document.createElement("input");
                        field.setAttribute("type", "hidden");
                        field.setAttribute("name", 'accessToken');
                        field.setAttribute("value", accessToken);
                        form.appendChild(field);

                        document.body.appendChild(form);
                        form.submit();

                    } else if (response.status === 'not_authorized') {
                        // the user is logged in to Facebook, 
                        // but has not authenticated your app
                    } else {
                        // the user isn't logged in to Facebook.
                    }
                });


            };

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

1 に答える 1

1

SDK自体を使用してログインするのではなく、ログインボタンを使用しているため、ボタン自体にscope設定されたパラメーターを介して許可を要求する必要があります。https://developers.facebook.com/docs/reference/plugins/を参照してください。ログインする/data-scope="…"

もう 1 つの方法は、ボタンを削除し、FB.login独自に作成したボタン/リンクで onclick を呼び出すことです。

于 2013-02-21T23:19:26.297 に答える