从< textarea&gt用fb.ui? [英] post message to facebook from <textarea> using fb.ui?

查看:144
本文介绍了从< textarea&gt用fb.ui?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读:

使用Facebook图简单地发布墙上的消息,只需javascript

我正在看对于类似的东西,

and i am looking for something similar,

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对于网站是超酷的...我想发布文本将被写在我的textarea与id =评论。

but instead of posting 'Facebook for Websites is super-cool'... i would like to post the text that will be written in my textarea with the id=comment.

所以用户进入网站,写入文本区域,按下一个触发对话框的按钮,对话框显示textarea中的文本。

so users enters site, writes int he text area, presses a button which triggers the dialog box, dialog box displays text from textarea.

我想我将需要添加一些额外的javascipt但是我的javascript是非常有限的。

i am guess i will need to add some extra javascipt with some getelementbyid and a onclick event, but my javascript is very limited.

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

solutions or suggestions will be greatly appreciated.~

谢谢

推荐答案

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

Here's a full working example:

<!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>

这篇关于从&lt; textarea&gt用fb.ui?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆