In this recipe, you'll learn how to post a link on a Facebook user's Timeline from a Spring web application.
Here are the steps to post a link on a Facebook user's Timeline:
In the
FacebookController
class, in thelogin()
method, addpublish_actions
to thescope
parameter:params.setScope("public_profile, publish_actions");
In the
fb()
method, in theif(facebook.isAuthorized())
block, create aFacebookLink
object with the link URL, title, caption, and description:FacebookLink link = new FacebookLink("http://jeromejaglale.com/", "Spring is easy with Spring Cookbook", "Spring Cookbook", "The recipes are understandable and actually work.");
Use the Facebook object to post the link:
facebook.feedOperations().postLink("This link was posted from a Spring web application.", link);
In your browser, go to
/fb
. Then, go to the user's Facebook account and verify that the link...