post message to facebook from <textarea> using fb.ui?
i have already read:
Using Facebook Graph to simply post a wall message with just javascript
and i am looking for something similar,
l>
<head&开发者_开发问答gt;
<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>
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.
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.~
thank you
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>
精彩评论