Diễn Đàn Hỗ Trợ FM
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.


[HỎI ĐÁP] Chức năng đăng nhập bằng facebook

Tác giả: - vào lúc:
Kou94
Bài viết : 134
Points : 210
Like : 12
Punbb
An toàn
Kou94MEM LV3
1/14/2018, 18:51
#1
[HỎI ĐÁP] Chức năng đăng nhập bằng facebook 110

[HỎI ĐÁP] Chức năng đăng nhập bằng facebook 210

Demo: http://www.congdongotakuviet.com
Nick: test123
Pass: test1234

Mình không hiểu sao nó vẫn không hiện. Mong mọi người dành ít thời gian để hỗ trợ giúp mình.

P/s: Tiện thể cho mình hỏi cách hiện button đăng nhập bằng facebook ở 1 nơi bất kỳ luôn nhé.
Admin
Bài viết : 431
Points : 820
Like : 120
Punbb
Quản trị
Status : test
AdminACP
1/15/2018, 17:04
#2
Kiểm tra xem có xung đột js với js nào trong forum không

còn vị trí thì dùng code sau nhé

Code:


<script>
  // This is called with the results from from FB.getLoginStatus().
  function statusChangeCallback(response) {
    console.log('statusChangeCallback');
    console.log(response);
    // The response object is returned with a status field that lets the
    // app know the current login status of the person.
    // Full docs on the response object can be found in the documentation
    // for FB.getLoginStatus().
    if (response.status === 'connected') {
      // Logged into your app and Facebook.
      testAPI();
    } else if (response.status === 'not_authorized') {
      // The person is logged into Facebook, but not your app.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into this app.';
    } else {
      // The person is not logged into Facebook, so we're not sure if
      // they are logged into this app or not.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into Facebook.';
    }
  }

  // This function is called when someone finishes with the Login
  // Button.  See the onlogin handler attached to it in the sample
  // code below.
  function checkLoginState() {
    FB.getLoginStatus(function(response) {
      statusChangeCallback(response);
    });
  }

  window.fbAsyncInit = function() {
  FB.init({
    appId      : '123456789',
    cookie    : true,  // enable cookies to allow the server to access
                        // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.1' // use version 2.1
  });

  // Now that we've initialized the JavaScript SDK, we call
  // FB.getLoginStatus().  This function gets the state of the
  // person visiting this page and can return one of three states to
  // the callback you provide.  They can be:
  //
  // 1. Logged into your app ('connected')
  // 2. Logged into Facebook, but not your app ('not_authorized')
  // 3. Not logged into Facebook and can't tell if they are logged into
  //    your app or not.
  //
  // These three cases are handled in the callback function.

  FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
  });

  };

  // Load the SDK asynchronously
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

  // Here we run a very simple test of the Graph API after login is
  // successful.  See statusChangeCallback() for when this call is made.
  function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      document.getElementById('status').innerHTML =
        'Chào mừng: ' + response.name + '!';
    });
  }
</script>
  <fb:login-button size="large" onlogin="window.location='/facebook_connect.forum'" v="2" scope="" login_text="Đăng nhập bằng tài khoản FaceBook" class=" fb_iframe_widget" fb-xfbml-state="rendered" fb-iframe-plugin-query="app_id=123456789&container_width=0&locale=vi_VN&login_text=%C4%90%C4%83ng%20nh%E1%BA%ADp%20b%E1%BA%B1ng%20t%C3%A0i%20kho%E1%BA%A3n%20FaceBook&sdk=joey&size=large"></fb:login-button>


Tìm tất cả id 123456789 thành id của bạn nhé