从 <textarea> 向 Facebook 发布消息使用 fb.ui? [英] post message to facebook from <textarea> using fb.ui?
问题描述
我已经读过:
使用 Facebook Graph仅使用 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 for Websites is super-cool'...我想发布将在我的 textarea 中使用 id=comment 写入的文本.
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.
所以用户进入站点,在文本区域写入,按下触发对话框的按钮,对话框显示来自文本区域的文本.
so users enters site, writes int he text area, presses a button which triggers the dialog box, dialog box displays text from textarea.
我想我需要添加一些带有 getelementbyid 和 onclick 事件的额外 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>
这篇关于从 <textarea> 向 Facebook 发布消息使用 fb.ui?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!