In this post we will see how to make a full wall post to a User's Profile or to a public facebook page using the Facbook javascript Graph API.
The wall post will contain this fields : a Message, Name, Description, Link, Picture and Caption.
After authenticating the User (
you need the publish_stream permission), here's what to do:
var params = {};
params['message'] = 'The message';
params['name'] = 'Name';
params['description'] = 'this is a description';
params['link'] = 'http://www.somelink.com/page.htm';
params['picture'] = 'http://www.somelink.com/img/pic.jpg';
params['caption'] = 'Caption of the Post';
FB.api('/me/feed', 'post', params, function(response) {
if (!response || response.error) {
// an error occured
alert(JSON.stringify(response.error));
} else {
// Done
alert('Published to stream');
}
});
If you want to post on a facebook page wall instead of users wall (you need to get manage_pages permission from the user), just replace the FB.api line with:
... FB.api('/page-id/feed', 'post', params, function(response) { ...
The example above will publish a post not a Link, if you want to post a Link/Url use this code:
var params = {};
params['message'] = 'The message';
params['link'] = 'http://www.somelink.com/page.htm';
FB.api('/me/links', 'post', params, function(response) {
if (!response || response.error) {
// an error occured
alert(JSON.stringify(response.error));
} else {
// Done
alert('Link Published to stream');
}
});