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.
GRAPH_API_URL
Constructor and Description |
---|
FacebookTemplate(String accessToken)
Create a new instance of FacebookTemplate.
|
FacebookTemplate(String accessToken,
String applicationNamespace) |
FacebookTemplate(String accessToken,
String applicationNamespace,
String appId) |
Modifier and Type | Method and Description |
---|---|
AchievementOperations |
achievementOperations()
API for working with achievements.
|
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.
|
void |
delete(String objectId,
String connectionType,
MultiValueMap<String,String> data)
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.
|
byte[] |
fetchImage(String objectId,
String connectionType,
Integer width,
Integer height)
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> T |
fetchObject(String objectId,
Class<T> type,
String... fields)
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) |
FriendOperations |
friendOperations()
API for performing operations with a user's set of friends.
|
String |
getApplicationNamespace() |
String |
getBaseGraphApiUrl() |
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.
|
void |
post(String objectId,
MultiValueMap<String,Object> data)
Publishes data to an object.
|
void |
post(String objectId,
String connectionType,
MultiValueMap<String,Object> 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.
|
RestOperations |
restOperations()
Returns the underlying
RestOperations object allowing for consumption of Facebook endpoints that may not be otherwise covered by the API binding. |
void |
setApiVersion(String apiVersion)
Set the Graph API version (e.g., "2.5").
|
void |
setRequestFactory(ClientHttpRequestFactory requestFactory) |
SocialContextOperations |
socialContextOperations()
API for working with social contexts.
|
TestUserOperations |
testUserOperations()
API for working with test users on Facebook.
|
UserOperations |
userOperations()
API for performing operations on Facebook user profiles.
|
afterPropertiesSet, getByteArrayMessageConverter, getFormMessageConverter, getMessageConverters, getRestTemplate, isAuthorized, postConstructionConfiguration, postProcess
public FacebookTemplate(String accessToken)
accessToken
- An access token given by Facebook after a successful OAuth 2 authentication (or through Facebook's JS library).public void setRequestFactory(ClientHttpRequestFactory requestFactory)
setRequestFactory
in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding
public void setApiVersion(String apiVersion)
apiVersion
- the API version. Default is "2.5".public AchievementOperations achievementOperations()
Facebook
achievementOperations
in interface Facebook
AchievementOperations
public UserOperations userOperations()
Facebook
userOperations
in interface Facebook
UserOperations
public LikeOperations likeOperations()
Facebook
likeOperations
in interface Facebook
LikeOperations
public FriendOperations friendOperations()
Facebook
friendOperations
in interface Facebook
FriendOperations
public FeedOperations feedOperations()
Facebook
feedOperations
in interface Facebook
FeedOperations
public GroupOperations groupOperations()
Facebook
groupOperations
in interface Facebook
GroupOperations
public CommentOperations commentOperations()
Facebook
commentOperations
in interface Facebook
CommentOperations
public EventOperations eventOperations()
Facebook
eventOperations
in interface Facebook
EventOperations
public MediaOperations mediaOperations()
Facebook
mediaOperations
in interface Facebook
MediaOperations
public PageOperations pageOperations()
Facebook
pageOperations
in interface Facebook
PageOperations
public RestOperations restOperations()
Facebook
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.restOperations
in interface Facebook
public OpenGraphOperations openGraphOperations()
Facebook
openGraphOperations
in interface Facebook
OpenGraphOperations
public SocialContextOperations socialContextOperations()
Facebook
socialContextOperations
in interface Facebook
SocialContextOperations
public String getApplicationNamespace()
getApplicationNamespace
in interface Facebook
getApplicationNamespace
in interface GraphApi
public TestUserOperations testUserOperations()
Facebook
testUserOperations
in interface Facebook
TestUserOperations
public <T> T fetchObject(String objectId, Class<T> type)
GraphApi
fetchObject
in interface GraphApi
T
- The Java type to bind the Facebook object toobjectId
- the Facebook object's IDtype
- the Java type to fetchpublic <T> T fetchObject(String objectId, Class<T> type, String... fields)
GraphApi
fetchObject
in interface GraphApi
T
- The Java type to bind the Facebook object toobjectId
- the Facebook object's IDtype
- the Java type to fetchfields
- the fields to include in the response.public <T> T fetchObject(String objectId, Class<T> type, MultiValueMap<String,String> queryParameters)
GraphApi
fetchObject
in interface GraphApi
T
- The Java type to bind the Facebook object toobjectId
- the Facebook object's IDtype
- the Java type to fetchqueryParameters
- query parameters to include in the requestpublic <T> PagedList<T> fetchConnections(String objectId, String connectionType, Class<T> type, String... fields)
GraphApi
fetchConnections
in interface GraphApi
T
- The Java type to bind the Facebook object toobjectId
- 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.public <T> PagedList<T> fetchConnections(String objectId, String connectionType, Class<T> type, MultiValueMap<String,String> queryParameters)
GraphApi
fetchConnections
in interface GraphApi
T
- The Java type to bind the Facebook object toobjectId
- 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 requestpublic <T> PagedList<T> fetchPagedConnections(String objectId, String connectionType, Class<T> type, MultiValueMap<String,String> queryParameters)
public <T> PagedList<T> fetchConnections(String objectId, String connectionType, Class<T> type, MultiValueMap<String,String> queryParameters, String... fields)
GraphApi
fetchConnections
in interface GraphApi
T
- The Java type to bind the Facebook object toobjectId
- 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 requestfields
- the fields to include in the response.public String getBaseGraphApiUrl()
getBaseGraphApiUrl
in interface GraphApi
public byte[] fetchImage(String objectId, String connectionType, ImageType type)
GraphApi
fetchImage
in interface GraphApi
objectId
- the object IDconnectionType
- the connection nametype
- the type of image to retrieve (eg., small, normal, large, or square)public byte[] fetchImage(String objectId, String connectionType, Integer width, Integer height)
GraphApi
fetchImage
in interface GraphApi
objectId
- the object IDconnectionType
- the connection namewidth
- desired width of the image (optional)height
- desired height of the image (optional)public String publish(String objectId, String connectionType, MultiValueMap<String,Object> data)
GraphApi
public void post(String objectId, MultiValueMap<String,Object> data)
GraphApi
public void post(String objectId, String connectionType, MultiValueMap<String,Object> data)
GraphApi
public void delete(String objectId)
GraphApi
public void delete(String objectId, String connectionType)
GraphApi
public void delete(String objectId, String connectionType, MultiValueMap<String,String> data)
GraphApi
protected org.springframework.social.oauth2.OAuth2Version getOAuth2Version()
getOAuth2Version
in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding
protected void configureRestTemplate(RestTemplate restTemplate)
configureRestTemplate
in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding
protected MappingJackson2HttpMessageConverter getJsonMessageConverter()
getJsonMessageConverter
in class org.springframework.social.oauth2.AbstractOAuth2ApiBinding