views:

73

answers:

1

Hi,

I got error occurred when trying to post to wall on facebook using the below code. It sometimes can post after the first login but always return error later on.

<?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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"&gt;
    <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  A: 

Why is your <script> tag before <html> tag? Put it inside <head> or <body>.

serg
I have tried your suggestion but I still got alert error occurred.