2010-09-11 102 views
0

我在使用下面的代碼嘗試發佈到Facebook牆上時發生錯誤。它有時可以在首次登錄後發佈,但以後總是會返回錯誤。FB.api()發生錯誤-FB undefined

<?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>  
+0

您的應用程序是否有權在牆上張貼? – FrEaKmAn 2010-09-11 10:54:48

+0

是的,我已將該權限授予我的應用程序 – user445044 2010-09-12 13:37:27

回答

1

爲什麼以前<html>標籤你<script>標籤?把它放進<head><body>

+0

我已經嘗試了您的建議,但仍發生警報錯誤。 – user445044 2010-09-12 13:36:55