3

Javascript SDK を使用して、Facebook からログイン ボタンを自分の Web サイトで動作させようとしています。ユーザーがログオンしている場合は、メール アドレスが返されます。これは機能します。しかし、Facebook のログイン ボタンがあるページには、自分の Web サイトの通常のログインもあります。(ユーザー名パスワード)。しかし、ログイン ページに移動すると、ページに自動的に Facebook ボタンが読み込まれ、Facebook ログイン ダイアログが表示されます。しかし、このボタンを自動的にロードしたくありません。ユーザーが常に Facebook のログイン ボタンを押さなければならないことを望みます。これは可能ですか?

これは私のコードです:

<script>
  window.fbAsyncInit = function() {
FB.init({
        appId: 'MY_APP_ID', // App ID
        status: true,
        cookie: true,
        xfbml: true,
        oauth: true,

});
FB.getLoginStatus(function(response) {
  FB.login(function(response) {
   if (response.authResponse) {
     FB.api('/me', function(response) {
       alert('Good to see you, ' + response.email + '.');
     });
   } else {
     alert('User cancelled login or did not fully authorize.');
   }
 });
});

// Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/en_US/all.js";
 d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>
4

1 に答える 1

6

FB.getLoginStatusメソッドは、ユーザーがログインしているかどうかを知るために使用されます

FB.loginログインページにアプリの認証と承認を求めるために使用されます。

FB.getLoginStatus メソッドを呼び出しており、応答を気にせず、常に fb.login ボタンを起動しています。

ユーザーに常にログインボタンをクリックさせたい場合は、使用しないでくださいFB.getLoginStatus

このコードを使用

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

      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : 'YOUR_APP_ID', // App ID
            channelUrl : '//WWW.YOUR_DOMAIN.COM/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>

      <div class="fb-login-button">Login with Facebook</div>

    </body>
 </html>

参考までに: https://developers.facebook.com/docs/guides/web/
認証セクションを確認してください

于 2012-06-27T09:55:35.920 に答える