如何使用HTML以编程方式将简单文本发布到FB墙?

时间:2011-04-01 21:19:41

标签: facebook

我想要做的是将一些简单的文字发布到用户的FB墙上(我的应用已经知道用户的ID)。

已经阅读了很多关于发布到FB墙的帖子,但仍然发现了。

从youtube视频的示例代码中,我创建了一个完整的代码集并发布到 FB dev论坛,我得到的错误信息是, “在调用FB.init()之前调用FB.getLoginStatus()”

这是我的代码的链接, http://forum.developers.facebook.net/viewtopic.php?id=94801

注意: 我们可以使用一个简单的HTML页面来测试这个......

怎么了?感谢。

1 个答案:

答案 0 :(得分:0)

这是我项目的facebook测试页面的源代码,包含一些常见的facebook任务的完整实现。唯一被编辑的是facebook app ID。显然,你没有我们的库,但在这种情况下,他们只是验证会话并绘制标题。

<html> 
    <head> 
    <meta charset="UTF-8" /> 
    <title>phyre Lux Client</title> 
    <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script> 
    <script type="text/javascript" src="../js/jquery-ui-1.8.5.custom.min.js"></script> 
    <script type="text/javascript" src="../phyrelib-clientside.js"></script> 
    <link type="text/css" href="../css/custom-theme/jquery-ui-1.8.5.custom.css" rel="stylesheet">   
    <link type="text/css" href="../css/phyre.css" rel="stylesheet"> 

                <script src="js/typeface.js"></script> 
                <script src="js/cicle_fina.typeface.js"></script> 
                </head> 
                <body onLoad='return 0;' id='luxDocBody' class='phyremodule'> 

<div id='fb-root'></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script type='text/javascript'> 
FB.init({appId: 'REDACTED', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
    if (response.session) {
      // A user has logged in, and a new cookie has been saved
    alert('yay');
    } else {
      // The user has logged out, and the cookie has been cleared
    alert('nay');
    }
  });

FB.ui(
   {
     method: 'stream.publish',
     message: 'getting educated about Facebook Connect',
     attachment: {
       name: 'Connect',
       caption: 'The Facebook Connect JavaScript SDK',
       description: (
         'A small JavaScript library that allows you to harness ' +
         'the power of Facebook, bringing the user\'s identity, ' +
         'social graph and distribution power to your site.'
       ),
       href: 'http://github.com/facebook/connect-js'
     },
     action_links: [
       { text: 'Code', href: 'http://github.com/facebook/connect-js' }
     ],
     user_message_prompt: 'Share your thoughts about Connect'
   },
   function(response) {
     if (response && response.post_id) {
       alert('Post was published.');
     } else {
       alert('Post was not published.');
     }
   }
 );

FB.getLoginStatus(function(response) {
  if (response.session) {
    // logged in and connected user, someone you know
    alert('yay');
  } else {
    // no user session available, someone you dont know
    alert('nay');
  }
});
</script> 
<fb:login-button></fb:login-button> 
</body> 
</html>