麻烦facebook sdk快速启动

时间:2014-03-20 22:26:43

标签: facebook

按此处指示https://developers.facebook.com/docs/javascript/quickstart

我从一个空白的HTML页面开始,只是HTML,Body标签和一个简单的Hello World。

我直接从快速入门页面复制并粘贴,但什么都没有(但是Hello World会加载)。 我有一个应用程序ID(我不确定是否应该包含{}或者不是,尝试了两种方式,没有变化。 我添加了“使用SDK添加社交插件”,“使用SDK触发Feed对话框”等部分中的代码,但没有添加任何内容。在CentOS / Apache上运行,服务器很好。不知道我错过了什么。思考? 谢谢你的时间。

PS页面可在此处查看来源:http://nex916.elementfx.com/purity3.html

2 个答案:

答案 0 :(得分:1)

也许以下内容会有所帮助?

<div id="fb-root"></div>

    <!-- Load the Facebook JavaScript SDK -->
    <script src="//connect.facebook.net/en_US/all.js"></script>

    <script type="text/javascript">

      // Initialize the Facebook JavaScript SDK
      FB.init({
        appId: 'YOUR_APP_ID',
        xfbml: true,
        status: true,
        cookie: true,
      });

      // Check if the current user is logged in and has authorized the app
      FB.getLoginStatus(checkLoginStatus);

      // Login in the current user via Facebook and ask for email permission
      function authUser() {
        FB.login(checkLoginStatus, {scope:'email'});
      }

      // Check the result of the user status and display login button if necessary
      function checkLoginStatus(response) {
        if(response && response.status == 'connected') {
          //alert('User is authorized');

          // Hide the login button
          document.getElementById('loginButton').style.display = 'none';

          // Now Personalize the User Experience
          //console.log('Access Token: ' + response.authResponse.accessToken);
        } else {
          //alert('User is not authorized');

          // Display the login button
          document.getElementById('loginButton').style.display = 'block';
        }
      }
          FB.ui(
      {
       method: 'feed',
       name: 'The Facebook SDK for Javascript',
       caption: 'Bringing Facebook to the desktop and mobile web',
       description: (
          'A small JavaScript library that allows you to harness ' +
          'the power of Facebook, bringing the user\'s identity, ' +
          'social graph and distribution power to your site.'
       ),
       link: 'https://developers.facebook.com/docs/reference/javascript/',
       picture: 'http://www.fbrell.com/public/f8.jpg'
      },
      function(response) {
        if (response && response.post_id) {
          alert('Post was published.');
        } else {
          alert('Post was not published.');
        }
      }
    );
    </script>
    <input id="loginButton" type="button" value="Ligin with Facebook" onclick="authUser();" /></div>
<div class="fb-like" data-send="true" data-width="450" data-show-faces="true"></div>

答案 1 :(得分:1)

您的JS中存在语法错误

  

SyntaxError:语法错误purity2.html:26

要解决此问题,请从};

中删除line 19
FB.Event.subscribe('auth.authResponseChange', function(response) {
    if (response.status === 'connected') {
      console.log('Logged in');
    } else {
      FB.login();
    }
  });
}; // this

它应该像

FB.Event.subscribe('auth.authResponseChange', function(response) {
    if (response.status === 'connected') {
      console.log('Logged in');
    } else {
      FB.login();
    }
  });

现在您的代码应该正常工作

相关问题