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

java.lang.Object
  extended by org.springframework.social.facebook.api.impl.FacebookTemplate
All Implemented Interfaces:
FacebookApi, GraphApi

public class FacebookTemplate
extends java.lang.Object
implements FacebookApi

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.


Field Summary
 
Fields inherited from interface org.springframework.social.facebook.api.GraphApi
CONNECTION_URL, GRAPH_API_URL, OBJECT_URL
 
Constructor Summary
FacebookTemplate(java.lang.String accessToken)
          Create a new instance of FacebookTemplate.
 
Method Summary
 CommentOperations commentOperations()
          API for reading and posting comments.
 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> 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 Java type via the given ResponseExtractor.
 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 type via the given ResponseExtractor.
 FriendOperations friendOperations()
          API for performing operations with a user's set of friends.
 RestTemplate getRestTemplate()
           
 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.
 PlacesOperations placesOperations()
          API for performing Facebook Places checkin operations.
 void post(java.lang.String objectId, java.lang.String connectionType, 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, MultiValueMap<java.lang.String,java.lang.String> data)
          Publishes data to an object's connection.
 UserOperations userOperations()
          API for performing operations on Facebook user profiles.
 
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

userOperations

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

Specified by:
userOperations in interface FacebookApi

placesOperations

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

Specified by:
placesOperations in interface FacebookApi

likeOperations

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

Specified by:
likeOperations in interface FacebookApi

friendOperations

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

Specified by:
friendOperations in interface FacebookApi

feedOperations

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

Specified by:
feedOperations in interface FacebookApi

groupOperations

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

Specified by:
groupOperations in interface FacebookApi

commentOperations

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

Specified by:
commentOperations in interface FacebookApi

eventOperations

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

Specified by:
eventOperations in interface FacebookApi

mediaOperations

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

Specified by:
mediaOperations in interface FacebookApi

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 type via the given ResponseExtractor. 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.

fetchConnections

public <T> 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 Java type via the given ResponseExtractor. 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 type.
type - the Java type to fetch
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(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 type
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,
                                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.

Specified by:
publish in interface GraphApi
Parameters:
objectId - the object ID to publish to.
connectionType - the connection type 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,
                 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 type 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 type

getRestTemplate

public RestTemplate getRestTemplate()