org.springframework.social.facebook
Class FacebookTemplate

java.lang.Object
  extended by org.springframework.social.facebook.FacebookTemplate
All Implemented Interfaces:
FacebookOperations

public class FacebookTemplate
extends java.lang.Object
implements FacebookOperations

This is the central class for interacting with Facebook.

All operations through Facebook require OAuth 2-based authentication. Therefore, FacebookTemplate must be given an access token at construction time.

The easiest way to get an access token is to use the XFBML <fb:login-button> tag to require the user to signin to Facebook. Then, after a successful signin, the access token can be found in the cookie whose name is "fbs_{application key}". In Spring MVC, the FacebookWebArgumentResolver can extract the access token from the cookie and make it available as a String argument to the controller method.

See Also:
FacebookWebArgumentResolver

Constructor Summary
FacebookTemplate(java.lang.String accessToken)
          Create a new instance of FacebookTemplate.
 
Method Summary
 java.util.List<java.lang.String> getFriendIds()
          Get a list of the user's friends.
 java.lang.String getProfileId()
          Retrieves the user's Facebook profile ID.
 byte[] getProfilePicture()
          Retrieves the current user's profile picture as an array of bytes.
 byte[] getProfilePicture(java.lang.String profileId)
          Retrieves a user's profile picture as an array of bytes.
 java.lang.String getProfileUrl()
          Retrieve the URL to the user's Facebook profile.
 FacebookProfile getUserProfile()
          Retrieve the current user's Facebook profile information.
 void publish(java.lang.String object, java.lang.String connection, MultiValueMap<java.lang.String,java.lang.String> data)
           Low-level publish-to-Facebook method for publishing any type of object supported by Facebook's API.
 void updateStatus(java.lang.String message)
          Posts a message to the current user's wall.
 void updateStatus(java.lang.String message, FacebookLink link)
          Posts a message to the current user's wall along with a link.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FacebookTemplate

public FacebookTemplate(java.lang.String accessToken)
Create a new instance of FacebookTemplate. This constructor creates the FacebookTemplate using a given access token.

Parameters:
accessToken - An access token given by Facebook after a successful OAuth 2 authentication (or through Facebook's JS library).
Method Detail

getProfileId

public java.lang.String getProfileId()
Description copied from interface: FacebookOperations
Retrieves the user's Facebook profile ID.

Specified by:
getProfileId in interface FacebookOperations
Returns:
the user's Facebook profile ID.

getProfileUrl

public java.lang.String getProfileUrl()
Description copied from interface: FacebookOperations
Retrieve the URL to the user's Facebook profile.

Specified by:
getProfileUrl in interface FacebookOperations
Returns:
the URL to the user's Facebook profile.

getUserProfile

public FacebookProfile getUserProfile()
Description copied from interface: FacebookOperations
Retrieve the current user's Facebook profile information.

Specified by:
getUserProfile in interface FacebookOperations
Returns:
the user's profile information.

getFriendIds

public java.util.List<java.lang.String> getFriendIds()
Description copied from interface: FacebookOperations
Get a list of the user's friends.

Specified by:
getFriendIds in interface FacebookOperations
Returns:
a list of Strings where each entry is the Facebook ID of one of the user's friends.

updateStatus

public void updateStatus(java.lang.String message)
Description copied from interface: FacebookOperations
Posts a message to the current user's wall.

Specified by:
updateStatus in interface FacebookOperations

updateStatus

public void updateStatus(java.lang.String message,
                         FacebookLink link)
Description copied from interface: FacebookOperations
Posts a message to the current user's wall along with a link.

Specified by:
updateStatus in interface FacebookOperations
Parameters:
message - The message to post
link - A link to be included in the status update

publish

public void publish(java.lang.String object,
                    java.lang.String connection,
                    MultiValueMap<java.lang.String,java.lang.String> data)
Description copied from interface: FacebookOperations

Low-level publish-to-Facebook method for publishing any type of object supported by Facebook's API.

Specified by:
publish in interface FacebookOperations
Parameters:
object - The ID of the object to publish to.
connection - The connection to be published.
data - The data to be published.

getProfilePicture

public byte[] getProfilePicture()
Description copied from interface: FacebookOperations
Retrieves the current user's profile picture as an array of bytes.

Specified by:
getProfilePicture in interface FacebookOperations
Returns:
the user's profile picture in bytes.

getProfilePicture

public byte[] getProfilePicture(java.lang.String profileId)
Description copied from interface: FacebookOperations
Retrieves a user's profile picture as an array of bytes.

Specified by:
getProfilePicture in interface FacebookOperations
Parameters:
profileId - the Facebook ID of the user.
Returns:
the user's profile picture in bytes.