Book Image

SPRING COOKBOOK

Book Image

SPRING COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. In the FacebookController class, in the login() method, add publish_actions to the scope parameter:

      params.setScope("public_profile, publish_actions");
  2. In the fb() method, in the if(facebook.isAuthorized() ) block, create a PostData object using the Facebook object:

    PostData postData = new PostData(facebook.userOperations().getUserProfile().getId());
  3. Initialize the different fields of the custom object:

    postData.message("Vegetables are good for you.");
    postData.link("http://jeromejaglale.com");
    postData.caption("Pasta and vegetables");
    postData.description("Carbs are fine...