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.


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(String accessToken)
          Create a new instance of FacebookTemplate.
FacebookTemplate(String accessToken, String applicationNamespace)
           
 
Method Summary
 CommentOperations commentOperations()
          API for reading and posting comments.
protected  void configureRestTemplate(RestTemplate restTemplate)
           
 void delete(String objectId)
          Deletes an object.
 void delete(String objectId, String connectionType)
          Deletes an object connection.
 EventOperations eventOperations()
          API for performing operations on events.
 FeedOperations feedOperations()
          API for performing operations on feeds.
<T> PagedList<T>
fetchConnections(String objectId, String connectionType, Class<T> type, MultiValueMap<String,String> queryParameters)
          Fetches connections, extracting them into a collection of the given Java type Requires appropriate permission to fetch the object connection.
<T> PagedList<T>
fetchConnections(String objectId, String connectionType, Class<T> type, MultiValueMap<String,String> queryParameters, String... fields)
          Fetches connections, extracting them into a collection of the given Java type Requires appropriate permission to fetch the object connection.
<T> PagedList<T>
fetchConnections(String objectId, String connectionType, Class<T> type, String... fields)
          Fetches connections, extracting them into a collection of the given Java type Requires appropriate permission to fetch the object connection.
 byte[] fetchImage(String objectId, String connectionType, ImageType type)
          Fetches an image as an array of bytes.
<T> T
fetchObject(String objectId, Class<T> type)
          Fetches an object, extracting it into the given Java type Requires appropriate permission to fetch the object.
<T> T
fetchObject(String objectId, Class<T> type, MultiValueMap<String,String> queryParameters)
          Fetches an object, extracting it into the given Java type Requires appropriate permission to fetch the object.
<T> PagedList<T>
fetchPagedConnections(String objectId, String connectionType, Class<T> type, MultiValueMap<String,String> queryParameters)
           
 FqlOperations fqlOperations()
          API for performing Facebook Query Language (FQL) queries.
 FriendOperations friendOperations()
          API for performing operations with a user's set of friends.
 String getApplicationNamespace()
           
protected  MappingJackson2HttpMessageConverter 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.
 OpenGraphOperations openGraphOperations()
          API for working with OpenGraph actions.
 PageOperations pageOperations()
          API for working with Facebook pages.
 PlacesOperations placesOperations()
          API for performing Facebook Places checkin operations.
 void post(String objectId, String connectionType, MultiValueMap<String,String> data)
          Publishes data to an object's connection.
 String publish(String objectId, String connectionType, MultiValueMap<String,Object> data)
          Publishes data to an object's connection.
 QuestionOperations questionOperations()
          API for performing question operations.
 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(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(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).

FacebookTemplate

public FacebookTemplate(String accessToken,
                        String applicationNamespace)
Method Detail

setRequestFactory

public void setRequestFactory(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 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

fqlOperations

public FqlOperations fqlOperations()
Description copied from interface: Facebook
API for performing Facebook Query Language (FQL) queries.

Specified by:
fqlOperations in interface Facebook

questionOperations

public QuestionOperations questionOperations()
Description copied from interface: Facebook
API for performing question operations.

Specified by:
questionOperations in interface Facebook

openGraphOperations

public OpenGraphOperations openGraphOperations()
Description copied from interface: Facebook
API for working with OpenGraph actions.

Specified by:
openGraphOperations in interface Facebook

getApplicationNamespace

public String getApplicationNamespace()
Specified by:
getApplicationNamespace in interface Facebook
Specified by:
getApplicationNamespace in interface GraphApi
Returns:
the application namespace that this FacebookTemplate was created for. May be null if no namespace was given.

fetchObject

public <T> T fetchObject(String objectId,
                         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(String objectId,
                         Class<T> type,
                         MultiValueMap<String,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> PagedList<T> fetchConnections(String objectId,
                                         String connectionType,
                                         Class<T> type,
                                         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> PagedList<T> fetchConnections(String objectId,
                                         String connectionType,
                                         Class<T> type,
                                         MultiValueMap<String,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.

fetchPagedConnections

public <T> PagedList<T> fetchPagedConnections(String objectId,
                                              String connectionType,
                                              Class<T> type,
                                              MultiValueMap<String,String> queryParameters)

fetchConnections

public <T> PagedList<T> fetchConnections(String objectId,
                                         String connectionType,
                                         Class<T> type,
                                         MultiValueMap<String,String> queryParameters,
                                         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.
queryParameters - query parameters to include in the request
fields - the fields to include in the response.
Returns:
a list of Java objects representing the Facebook objects in the connections.

fetchImage

public byte[] fetchImage(String objectId,
                         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 String publish(String objectId,
                      String connectionType,
                      MultiValueMap<String,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(String objectId,
                 String connectionType,
                 MultiValueMap<String,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(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(String objectId,
                   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(RestTemplate restTemplate)
Overrides:
configureRestTemplate in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding

getJsonMessageConverter

protected MappingJackson2HttpMessageConverter getJsonMessageConverter()
Overrides:
getJsonMessageConverter in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding