Spring Social Facebook

org.springframework.social.facebook.api.impl
Class FacebookTemplate

java.lang.Object
  extended by org.springframework.social.oauth2.AbstractOAuth2ApiBinding
      extended by org.springframework.social.facebook.api.impl.FacebookTemplate
All Implemented Interfaces:
org.springframework.social.ApiBinding, Facebook, GraphApi

public class FacebookTemplate
extends org.springframework.social.oauth2.AbstractOAuth2ApiBinding
implements Facebook

This is the central class for interacting with Facebook.

There are some operations, such as searching, that do not require OAuth authentication. In those cases, you may use a FacebookTemplate that is created through the default constructor and without any OAuth details. Attempts to perform secured operations through such an instance, however, will result in NotAuthorizedException being thrown.

Author:
Craig Walls

Field Summary
 
Fields inherited from interface org.springframework.social.facebook.api.GraphApi
GRAPH_API_URL
 
Constructor Summary
FacebookTemplate()
          Create a new instance of FacebookTemplate.
FacebookTemplate(java.lang.String accessToken)
          Create a new instance of FacebookTemplate.
 
Method Summary
 CommentOperations commentOperations()
          API for reading and posting comments.
protected  void configureRestTemplate(org.springframework.web.client.RestTemplate restTemplate)
           
 void delete(java.lang.String objectId)
          Deletes an object.
 void delete(java.lang.String objectId, java.lang.String connectionType)
          Deletes an object connection.
 EventOperations eventOperations()
          API for performing operations on events.
 FeedOperations feedOperations()
          API for performing operations on feeds.
<T> java.util.List<T>
fetchConnections(java.lang.String objectId, java.lang.String connectionType, java.lang.Class<T> type, org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> queryParameters)
          Fetches connections, extracting them into a collection of the given Java type Requires appropriate permission to fetch the object connection.
<T> java.util.List<T>
fetchConnections(java.lang.String objectId, java.lang.String connectionType, java.lang.Class<T> type, java.lang.String... fields)
          Fetches connections, extracting them into a collection of the given Java type Requires appropriate permission to fetch the object connection.
 byte[] fetchImage(java.lang.String objectId, java.lang.String connectionType, ImageType type)
          Fetches an image as an array of bytes.
<T> T
fetchObject(java.lang.String objectId, java.lang.Class<T> type)
          Fetches an object, extracting it into the given Java type Requires appropriate permission to fetch the object.
<T> T
fetchObject(java.lang.String objectId, java.lang.Class<T> type, org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> queryParameters)
          Fetches an object, extracting it into the given Java type Requires appropriate permission to fetch the object.
 FriendOperations friendOperations()
          API for performing operations with a user's set of friends.
protected  org.springframework.http.converter.json.MappingJacksonHttpMessageConverter getJsonMessageConverter()
           
protected  org.springframework.social.oauth2.OAuth2Version getOAuth2Version()
           
 GroupOperations groupOperations()
          API for performing operations on groups.
 LikeOperations likeOperations()
          API for performing operations against user likes and interests.
 MediaOperations mediaOperations()
          API for performing operations on albums, photos, and videos.
 PageOperations pageOperations()
          API for working with Facebook pages.
 PlacesOperations placesOperations()
          API for performing Facebook Places checkin operations.
 void post(java.lang.String objectId, java.lang.String connectionType, org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> data)
          Publishes data to an object's connection.
 java.lang.String publish(java.lang.String objectId, java.lang.String connectionType, org.springframework.util.MultiValueMap<java.lang.String,java.lang.Object> data)
          Publishes data to an object's connection.
 org.springframework.web.client.RestOperations restOperations()
          Returns the underlying RestOperations object allowing for consumption of Facebook endpoints that may not be otherwise covered by the API binding.
 void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
           
 UserOperations userOperations()
          API for performing operations on Facebook user profiles.
 
Methods inherited from class org.springframework.social.oauth2.AbstractOAuth2ApiBinding
getByteArrayMessageConverter, getFormMessageConverter, getMessageConverters, getRestTemplate, isAuthorized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.social.ApiBinding
isAuthorized
 

Constructor Detail

FacebookTemplate

public FacebookTemplate()
Create a new instance of FacebookTemplate. This constructor creates a new FacebookTemplate able to perform unauthenticated operations against Facebook's Graph API. Some operations do not require OAuth authentication. For example, retrieving a specified user's profile or feed does not require authentication (although the data returned will be limited to what is publicly available). A FacebookTemplate created with this constructor will support those operations. Those operations requiring authentication will throw NotAuthorizedException.


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

setRequestFactory

public void setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory requestFactory)
Overrides:
setRequestFactory in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding

userOperations

public UserOperations userOperations()
Description copied from interface: Facebook
API for performing operations on Facebook user profiles.

Specified by:
userOperations in interface Facebook

placesOperations

public PlacesOperations placesOperations()
Description copied from interface: Facebook
API for performing Facebook Places checkin operations.

Specified by:
placesOperations in interface Facebook

likeOperations

public LikeOperations likeOperations()
Description copied from interface: Facebook
API for performing operations against user likes and interests.

Specified by:
likeOperations in interface Facebook

friendOperations

public FriendOperations friendOperations()
Description copied from interface: Facebook
API for performing operations with a user's set of friends.

Specified by:
friendOperations in interface Facebook

feedOperations

public FeedOperations feedOperations()
Description copied from interface: Facebook
API for performing operations on feeds.

Specified by:
feedOperations in interface Facebook

groupOperations

public GroupOperations groupOperations()
Description copied from interface: Facebook
API for performing operations on groups.

Specified by:
groupOperations in interface Facebook

commentOperations

public CommentOperations commentOperations()
Description copied from interface: Facebook
API for reading and posting comments.

Specified by:
commentOperations in interface Facebook

eventOperations

public EventOperations eventOperations()
Description copied from interface: Facebook
API for performing operations on events.

Specified by:
eventOperations in interface Facebook

mediaOperations

public MediaOperations mediaOperations()
Description copied from interface: Facebook
API for performing operations on albums, photos, and videos.

Specified by:
mediaOperations in interface Facebook

pageOperations

public PageOperations pageOperations()
Description copied from interface: Facebook
API for working with Facebook pages.

Specified by:
pageOperations in interface Facebook

restOperations

public org.springframework.web.client.RestOperations restOperations()
Description copied from interface: Facebook
Returns the underlying RestOperations object allowing for consumption of Facebook endpoints that may not be otherwise covered by the API binding. The RestOperations object returned is configured to include an OAuth 2 "Authorization" header on all requests.

Specified by:
restOperations in interface Facebook

fetchObject

public <T> T fetchObject(java.lang.String objectId,
                         java.lang.Class<T> type)
Description copied from interface: GraphApi
Fetches an object, extracting it into the given Java type Requires appropriate permission to fetch the object.

Specified by:
fetchObject in interface GraphApi
Parameters:
objectId - the Facebook object's ID
type - the Java type to fetch
Returns:
an Java object representing the requested Facebook object.

fetchObject

public <T> T fetchObject(java.lang.String objectId,
                         java.lang.Class<T> type,
                         org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> queryParameters)
Description copied from interface: GraphApi
Fetches an object, extracting it into the given Java type Requires appropriate permission to fetch the object.

Specified by:
fetchObject in interface GraphApi
Parameters:
objectId - the Facebook object's ID
type - the Java type to fetch
queryParameters - query parameters to include in the request
Returns:
an Java object representing the requested Facebook object.

fetchConnections

public <T> java.util.List<T> fetchConnections(java.lang.String objectId,
                                              java.lang.String connectionType,
                                              java.lang.Class<T> type,
                                              java.lang.String... fields)
Description copied from interface: GraphApi
Fetches connections, extracting them into a collection of the given Java type Requires appropriate permission to fetch the object connection.

Specified by:
fetchConnections in interface GraphApi
Parameters:
objectId - the ID of the object to retrieve the connections for.
connectionType - the connection name.
type - the Java type of each connection.
fields - the fields to include in the response.
Returns:
a list of Java objects representing the Facebook objects in the connections.

fetchConnections

public <T> java.util.List<T> fetchConnections(java.lang.String objectId,
                                              java.lang.String connectionType,
                                              java.lang.Class<T> type,
                                              org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> queryParameters)
Description copied from interface: GraphApi
Fetches connections, extracting them into a collection of the given Java type Requires appropriate permission to fetch the object connection.

Specified by:
fetchConnections in interface GraphApi
Parameters:
objectId - the ID of the object to retrieve the connections for.
connectionType - the connection name.
type - the Java type of each connection.
queryParameters - query parameters to include in the request
Returns:
a list of Java objects representing the Facebook objects in the connections.

fetchImage

public byte[] fetchImage(java.lang.String objectId,
                         java.lang.String connectionType,
                         ImageType type)
Description copied from interface: GraphApi
Fetches an image as an array of bytes.

Specified by:
fetchImage in interface GraphApi
Parameters:
objectId - the object ID
connectionType - the connection name
type - the type of image to retrieve (eg., small, normal, large, or square)
Returns:
an image as an array of bytes.

publish

public java.lang.String publish(java.lang.String objectId,
                                java.lang.String connectionType,
                                org.springframework.util.MultiValueMap<java.lang.String,java.lang.Object> data)
Description copied from interface: GraphApi
Publishes data to an object's connection. Requires appropriate permission to publish to the object connection.

Specified by:
publish in interface GraphApi
Parameters:
objectId - the object ID to publish to.
connectionType - the connection name to publish to.
data - the data to publish to the connection.
Returns:
the ID of the newly published object.

post

public void post(java.lang.String objectId,
                 java.lang.String connectionType,
                 org.springframework.util.MultiValueMap<java.lang.String,java.lang.String> data)
Description copied from interface: GraphApi
Publishes data to an object's connection. Requires appropriate permission to publish to the object connection. This differs from publish() only in that it doesn't attempt to extract the ID from the response. This is because some publish operations do not return an ID in the response.

Specified by:
post in interface GraphApi
Parameters:
objectId - the object ID to publish to.
connectionType - the connection name to publish to.
data - the data to publish to the connection.

delete

public void delete(java.lang.String objectId)
Description copied from interface: GraphApi
Deletes an object. Requires appropriate permission to delete the object.

Specified by:
delete in interface GraphApi
Parameters:
objectId - the object ID

delete

public void delete(java.lang.String objectId,
                   java.lang.String connectionType)
Description copied from interface: GraphApi
Deletes an object connection. Requires appropriate permission to delete the object connection.

Specified by:
delete in interface GraphApi
Parameters:
objectId - the object ID
connectionType - the connection name

getOAuth2Version

protected org.springframework.social.oauth2.OAuth2Version getOAuth2Version()
Overrides:
getOAuth2Version in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding

configureRestTemplate

protected void configureRestTemplate(org.springframework.web.client.RestTemplate restTemplate)
Overrides:
configureRestTemplate in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding

getJsonMessageConverter

protected org.springframework.http.converter.json.MappingJacksonHttpMessageConverter getJsonMessageConverter()
Overrides:
getJsonMessageConverter in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding

Spring Social Facebook