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 link to Facebook


In this recipe, you'll learn how to post a link on a Facebook user's Timeline from a Spring web application.

Getting ready

This recipe uses the code from the Connecting to Facebook recipe.

How to do it…

Here are the steps to post a link on a Facebook user's Timeline:

  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 FacebookLink 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.");
  3. Use the Facebook object to post the link:

    facebook.feedOperations().postLink("This link was posted from a Spring web application.", link);
  4. In your browser, go to /fb. Then, go to the user's Facebook account and verify that the link...