【问题标题】:post message to facebook from <textarea> using fb.ui?使用 fb.ui 从 <textarea> 向 facebook 发布消息?
【发布时间】:2011-07-15 09:55:07
【问题描述】:

我已经读过了:

Using Facebook Graph to simply post a wall message with just javascript

我正在寻找类似的东西,

l>
<head>
  <title>My Facebook Login Page</title>
</head>
<body>
  <div id="fb-root"></div>
  <script src="http://connect.facebook.net/en_US/all.js"></script>
  <script>
     FB.init({ 
        appId:'147622691*******', cookie:true, 
        status:true, xfbml:true 
     });

      FB.ui({ method: 'feed', 
        message: 'Facebook for Websites is super-cool'});

  </script>
  <fb:login-button perms="read_stream,publish_stream">Login with Facebook</fb:login-button>


<div id="content"></div>
<form>    <textarea name="text" id="comment"></textarea> 
<a href="#" id="submit_comment">submit</a></form>


</body>

但不是发布“用于网站的 Facebook 非常酷”...我想发布将在我的文本区域中写入 id=comment 的文本。

所以用户进入站点,在文本区域中写入,按下触发对话框的按钮,对话框显示来自文本区域的文本。

我想我需要添加一些额外的 javascipt 以及一些 getelementbyid 和一个 onclick 事件,但我的 javascript 非常有限。

解决方案或建议将不胜感激。~

谢谢

【问题讨论】:

    标签: javascript api post facebook


    【解决方案1】:

    这是一个完整的工作示例:

    <!doctype html>
    <html xmlns:fb="http://www.facebook.com/2008/fbml">
      <head>
        <title>JS-SDK FB.ui Test</title>
      </head>
      <body>
        <div id="fb-root"></div>
        <script>
          window.fbAsyncInit = function() {
            FB.init({
              appId   : 'XXXXXXXXXXXX',
              status  : true,
              cookie  : true,
              xfbml   : true
            });
    
            FB.Event.subscribe('auth.login', gotStatus);
    
            FB.Event.subscribe('auth.sessionChange', gotStatus);
          };
    
          function post(form) {
            if(form.comment.value.length) {
                FB.getLoginStatus(function(resp) {
                    if (resp.session) {
                        FB.ui(
                            {
                                method: 'feed',
                                message: form.comment.value
                            },
                            function(response) {
                                if (response && response.post_id) {
                                    alert('Post was published.');
                                } else {
                                    alert('Post was not published.');
                                }
                            }
                        );
                    } else {
                        alert("Please Login!");
                    }
                });
            } else {
                alert("You need to write something first!")
            }
            return false;
          }
            function gotStatus(response) {
                if(response.session)
                    document.getElementById('login-btn').disabled = true;
                else
                    document.getElementById('login-btn').disabled = false;
            }
          (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>
        <input  type="button"
                id="login-btn"
                value="Publish Stream"
                onclick="FB.login(gotStatus, {perms: 'publish_stream'})" />
        <form onSubmit="return post(this);">
            <textarea name="text" id="comment"></textarea>
            <input type="submit" value="Submit" />
        </form>
      </body>
    </html>
    

    【讨论】:

    • @iafour :您的回答很好,但不起作用(不再起作用?)。我得到一个带有“分享”或“取消”按钮的 Facebook 预览“窗口”,但 textarea id="feedform_user_message" 是空的……我该如何解决这个问题?
    • facebook 已弃用此选项....您无法在 facebook stackoverflow.com/questions/13899219/… 中预填消息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    相关资源
    最近更新 更多