Posting a custom object to Facebook
In this recipe, you'll learn how to post a custom object to a Facebook user's Timeline from a Spring web application. A custom object is a link with more customizable options: picture, privacy, and location. In this recipe, we will add a picture to a link.
Getting ready
This recipe uses the code from the Connecting to Facebook recipe.
How to do it…
Here are the steps to post a custom object:
- 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 aPostData
object using the Facebook object:PostData postData = new PostData(facebook.userOperations().getUserProfile().getId());
- Initialize the different fields of the custom object:
postData.message("Vegetables are good for you."); postData.link("http://jeromejaglale.com"); postData.caption("Pasta and...