墙柱问题

Wallpost problems?

本文关键字:问题      更新时间:2023-09-26

我正试图用我的fb应用程序制作wallpost。我的代码(下面)不会给出eny错误,但它不会发布任何内容。有人能帮我吗=P

应用程序文件(index.php):

<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '1234567890', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    // Additional initialization code here
  };
  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>

<a href="#" onClick="postToFacebook()">Post to Facebook</a>
<script>
function postToFacebook() {
    var body = 'Reading Connect JS documentation';
    FB.api('/me/feed', 'post', { body: body, message: 'My message is ...' }, function(response) {
      if (!response || response.error) {
        alert('Error occured');
      } else {
        alert('Post ID: ' + response);
      }
    });
}
</script>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : 'YOUR APP ID GOES HERE',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
  };
  (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>

服务器中的通道文件(channel.php):

 <?php
 $cache_expire = 60*60*24*365;
 header("Pragma: public");
 header("Cache-Control: max-age=".$cache_expire);
 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');
 ?>
 <script src="//connect.facebook.net/en_US/all.js"></script>

为什么要尝试初始化Facebook脚本两次?:)下面是一个工作代码的示例:如何让FB.api(';/me/feed';,';post';,…工作?请注意,用户需要先对应用程序进行授权,然后才能进行FB.api调用。你可以通过使用FB.login来做到这一点,例如:http://developers.facebook.com/docs/reference/javascript/FB.login/并使用FBgetLoginStats()检查用户是否真的连接到了您的应用程序:http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/希望这能帮助