FB.api()发生错误 - FB未定义

时间:2010-09-11 10:37:09

标签: javascript facebook

我尝试使用以下代码在Facebook上发布到墙上时发生错误。它有时可以在第一次登录后发布,但以后总是会返回错误。

<?php

  include_once "include/settings.php";
  //include_once "include/messages.php";
  if(isset($_GET["access_token"]))
  {
    $access_token = $_GET["access_token"];
  }

  //$msg = $msg_en;
?>
<script language="javascript">
  function publishToWall(){

    var params = {};

    params['message'] = 'message';

    alert('<?php echo $access_token; ?>');
    FB.api('/me/feed', 'post', { message: 'test' }, function(response) {

        if (!response || response.error) {
            alert('Error occured');
        } else {
            alert('Post ID: ' + response);
        }
    });

  }
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
        <title></title>
        <!--<link rel="stylesheet" href="css/style.css">-->

    </head>
    <body>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId  : 'YOUR APP ID',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml  : true  // parse XFBML
          });
          publishToWall();
        };

        (function() {
          var e = document.createElement('script');
          e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
          e.async = true;
          document.getElementById('fb-root').appendChild(e);
        }());
      </script>
    </body>
</html>     

1 个答案:

答案 0 :(得分:1)

为什么<script>标记在<html>标记之前?将其放在<head><body>