Facebook Connect中的API密钥错误(javascript sdk)

Muh*_*sir 7 javascript sdk facebook login connect

我正在尝试在网站上实施Facebook Connect.我正在尝试使用Facebok的Javascript SDK.我是新手,不幸的是,Facebook WIKI提供的大多数链接已经过时了......返回404未找到.无论如何,我在结束前添加了这段代码</body>:

<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
 <div id="fb-root"></div>
 <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"> </script>
 <script src="http://connect.facebook.net/en_US/all.js"></script>
 <script>
   FB.init({
     appId  : '12344', // my real app id is here
     status : true, // check login status
     cookie : true, // enable cookies to allow the server to access the session
     xfbml  : false  // parse XFBML
   });

   FB.login(function(response) {
  if (response.session) {
    if (response.perms) {
        alert('user is logged in and granted some permissions');
      // user is logged in and granted some permissions.
      // perms is a comma separated list of granted permissions
    } else {
        alert('user is logged in, but did not grant any permissions');
      // user is logged in, but did not grant any permissions
    }
  } else {
        alert('user is not logged in');
    // user is not logged in
  }
}, {perms:'email'});
 </script>
Run Code Online (Sandbox Code Playgroud)

我在同一页面中的其他地方(在上述脚本之前)有一个登录按钮,其中包含:

<fb:login-button v="2">Connect with Facebook</fb:login-button>
Run Code Online (Sandbox Code Playgroud)

此按钮呈现为普通的fb连接按钮,单击它会按正常情况打开一个新的弹出窗口.问题是它显示'指定了无效的api密钥'错误.在检查弹出的地址栏时,我看到api_key = undefined传递给它:(

对此有何想法?我正在尝试解决这个问题,最近5个小时...请帮助我找出为什么没有正确的API密钥传递给弹出窗口.

提前致谢.

Man*_*tto 4

我正在做同样的事情,并且我发现了一个非常容易实现和理解的示例(这里使用 jQuery,但您可以在没有库的情况下执行相同的操作):

<body>
  <div>
    <button id="login">Login</button>
    <button id="disconnect">Disconnect</button>
  </div>
  <div id="user-info" style="display: none;"></div>

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

  <div id="fb-root"></div>
  <script src="http://connect.facebook.net/en_US/all.js"></script>
  <script>
    // initialize the library with the API key
    FB.init({ appId  : '12344' });

    // fetch the status on load
    FB.getLoginStatus(handleSessionResponse);

    $('#login').bind('click', function() {
      FB.login(handleSessionResponse);
    });

    $('#disconnect').bind('click', function() {
      FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
        clearDisplay();
      });
    });

    // no user, clear display
    function clearDisplay() {
      $('#user-info').hide('fast');
    }

    // handle a session response from any of the auth related calls
    function handleSessionResponse(response) {
      // if we dont have a session, just hide the user info
      if (!response.session) {
        clearDisplay();
        return;
      }

      // if we have a session, query for the user's profile picture and name
      FB.api(
        {
          method: 'fql.query',
          query: 'SELECT name, pic FROM profile WHERE id=' + FB.getSession().uid
        },
        function(response) {
          var user = response[0];
          $('#user-info').html('<img src="' + user.pic + '">' + user.name).show('fast');
        }
      );
    }
  </script>
</body>
Run Code Online (Sandbox Code Playgroud)

在这里查看完整代码,在这里您可以找到其他资源。