0

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">
<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>     
2
  • Does your application have rights to post on wall? Commented Sep 11, 2010 at 10:54
  • Yes, I have granted that permission to my application Commented Sep 12, 2010 at 13:37

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.