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

Connecting to Facebook


Facebook allows access to a user account through an OAuth workflow; from our web application, the user is redirected to a Facebook page to authorize our Facebook app to access his/her account. The user is then redirected back to our web application. In this recipe, we'll implement this OAuth workflow.

Getting ready

You need an existing Facebook app. Refer to the Creating a Facebook app and Creating a test Facebook app and test users recipes.

We will use a JSP so make sure that the Maven dependency for JSTL is declared in your pom.xml file and the corresponding ViewResolver bean is declared in your Spring configuration class. For more details, refer to the Using a JSP view recipe in the Chapter 3, Using Controllers and Views.

How to do it…

Here are the steps to implement the Facebook OAuth workflow:

  1. Add the Maven dependencies for Spring Social and Spring Social Facebook in pom.xml:

    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId...