com.restfb
Class DefaultFacebookClient

java.lang.Object
  extended by com.restfb.DefaultFacebookClient
All Implemented Interfaces:
FacebookClient

public class DefaultFacebookClient
extends Object
implements FacebookClient

Default implementation of a Facebook Graph API client.

Author:
Mark Allen

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.restfb.FacebookClient
FacebookClient.AccessToken
 
Constructor Summary
DefaultFacebookClient()
          Creates a Facebook Graph API client with no access token.
DefaultFacebookClient(String accessToken)
          Creates a Facebook Graph API client with the given accessToken.
DefaultFacebookClient(String accessToken, WebRequestor webRequestor, JsonMapper jsonMapper)
          Creates a Facebook Graph API client with the given accessToken, webRequestor, and jsonMapper.
 
Method Summary
 List<FacebookClient.AccessToken> convertSessionKeysToAccessTokens(String appId, String secretKey, String... sessionKeys)
          Converts an arbitrary number of sessionKeys to OAuth access tokens.
 boolean deleteObject(String object)
          Performs a Graph API delete operation on the given object.
<T> T
executeMultiquery(Map<String,String> queries, Class<T> objectType, Parameter... parameters)
          Executes an FQL multiquery, which allows you to batch multiple queries into a single request.
<T> List<T>
executeQuery(String query, Class<T> objectType, Parameter... parameters)
          Executes an FQL query, mapping the resultset to a List of instances of objectType.
<T> Connection<T>
fetchConnection(String connection, Class<T> connectionType, Parameter... parameters)
          Fetches a Graph API Connection type, mapping the result to an instance of connectionType.
<T> Connection<T>
fetchConnectionPage(String connectionPageUrl, Class<T> connectionType)
          Fetches a previous/next page of a Graph API Connection type, mapping the result to an instance of connectionType.
<T> T
fetchObject(String object, Class<T> objectType, Parameter... parameters)
          Fetches a single Graph API object, mapping the result to an instance of objectType.
<T> T
fetchObjects(List<String> ids, Class<T> objectType, Parameter... parameters)
          Fetches multiple Graph API objects in a single call, mapping the results to an instance of objectType.
<T> T
publish(String connection, Class<T> objectType, InputStream binaryAttachment, Parameter... parameters)
          Performs a Graph API publish operation on the given connection and includes a file - a photo, for example - in the publish request, and mapping the result to an instance of objectType.
<T> T
publish(String connection, Class<T> objectType, Parameter... parameters)
          Performs a Graph API publish operation on the given connection, mapping the result to an instance of objectType.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFacebookClient

public DefaultFacebookClient()
Creates a Facebook Graph API client with no access token.

Without an access token, you can view and search public graph data but can't do much else.


DefaultFacebookClient

public DefaultFacebookClient(String accessToken)
Creates a Facebook Graph API client with the given accessToken.

Parameters:
accessToken - A Facebook OAuth access token.

DefaultFacebookClient

public DefaultFacebookClient(String accessToken,
                             WebRequestor webRequestor,
                             JsonMapper jsonMapper)
Creates a Facebook Graph API client with the given accessToken, webRequestor, and jsonMapper.

Parameters:
accessToken - A Facebook OAuth access token.
webRequestor - The WebRequestor implementation to use for sending requests to the API endpoint.
jsonMapper - The JsonMapper implementation to use for mapping API response JSON to Java objects.
Throws:
NullPointerException - If jsonMapper or webRequestor is null.
Method Detail

deleteObject

public boolean deleteObject(String object)
Description copied from interface: FacebookClient
Performs a Graph API delete operation on the given object.

Specified by:
deleteObject in interface FacebookClient
Parameters:
object - The ID of the object to delete.
Returns:
true if Facebook indicated that the object was successfully deleted, false otherwise.
See Also:
FacebookClient.deleteObject(java.lang.String)

fetchConnection

public <T> Connection<T> fetchConnection(String connection,
                                         Class<T> connectionType,
                                         Parameter... parameters)
Description copied from interface: FacebookClient
Fetches a Graph API Connection type, mapping the result to an instance of connectionType.

Specified by:
fetchConnection in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
connection - The name of the connection, e.g. "me/feed".
connectionType - Connection type token.
parameters - URL parameters to include in the API call (optional).
Returns:
An instance of type connectionType which contains the requested Connection's data.
See Also:
FacebookClient.fetchConnection(java.lang.String, java.lang.Class, com.restfb.Parameter[])

fetchConnectionPage

public <T> Connection<T> fetchConnectionPage(String connectionPageUrl,
                                             Class<T> connectionType)
Description copied from interface: FacebookClient
Fetches a previous/next page of a Graph API Connection type, mapping the result to an instance of connectionType.

Specified by:
fetchConnectionPage in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
connectionPageUrl - The URL of the connection page to fetch, usually retrieved via Connection.getPreviousPageUrl() or Connection.getNextPageUrl().
connectionType - Connection type token.
Returns:
An instance of type connectionType which contains the requested Connection's data.
See Also:
FacebookClient.fetchConnectionPage(java.lang.String, java.lang.Class)

fetchObject

public <T> T fetchObject(String object,
                         Class<T> objectType,
                         Parameter... parameters)
Description copied from interface: FacebookClient
Fetches a single Graph API object, mapping the result to an instance of objectType.

Specified by:
fetchObject in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
object - ID of the object to fetch, e.g. "me".
objectType - Object type token.
parameters - URL parameters to include in the API call (optional).
Returns:
An instance of type objectType which contains the requested object's data.
See Also:
FacebookClient.fetchObject(java.lang.String, java.lang.Class, com.restfb.Parameter[])

fetchObjects

public <T> T fetchObjects(List<String> ids,
                          Class<T> objectType,
                          Parameter... parameters)
Description copied from interface: FacebookClient
Fetches multiple Graph API objects in a single call, mapping the results to an instance of objectType.

You'll need to write your own container type (objectType) to hold the results. See http://restfb.com for an example of how to do this.

Specified by:
fetchObjects in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
ids - IDs of the objects to fetch, e.g. "me", "arjun".
objectType - Object type token.
parameters - URL parameters to include in the API call (optional).
Returns:
An instance of type objectType which contains the requested objects' data.
See Also:
FacebookClient.fetchObjects(java.util.List, java.lang.Class, com.restfb.Parameter[])

publish

public <T> T publish(String connection,
                     Class<T> objectType,
                     InputStream binaryAttachment,
                     Parameter... parameters)
Description copied from interface: FacebookClient
Performs a Graph API publish operation on the given connection and includes a file - a photo, for example - in the publish request, and mapping the result to an instance of objectType.

Specified by:
publish in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
connection - The Connection to publish to.
objectType - Object type token.
binaryAttachment - The file to include in the publish request - a photo, for example.
parameters - URL parameters to include in the API call.
Returns:
An instance of type objectType which contains the Facebook response to your publish request.
See Also:
FacebookClient.publish(java.lang.String, java.lang.Class, java.io.InputStream, com.restfb.Parameter[])

publish

public <T> T publish(String connection,
                     Class<T> objectType,
                     Parameter... parameters)
Description copied from interface: FacebookClient
Performs a Graph API publish operation on the given connection, mapping the result to an instance of objectType.

Specified by:
publish in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
connection - The Connection to publish to.
objectType - Object type token.
parameters - URL parameters to include in the API call.
Returns:
An instance of type objectType which contains the Facebook response to your publish request.
See Also:
FacebookClient.publish(java.lang.String, java.lang.Class, com.restfb.Parameter[])

executeMultiquery

public <T> T executeMultiquery(Map<String,String> queries,
                               Class<T> objectType,
                               Parameter... parameters)
Description copied from interface: FacebookClient
Executes an FQL multiquery, which allows you to batch multiple queries into a single request.

You'll need to write your own container type (objectType) to hold the results. See http://restfb.com for an example of how to do this.

Specified by:
executeMultiquery in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
queries - A mapping of query names to queries. This is marshaled to JSON and sent over the wire to the Facebook API endpoint as the queries parameter.
objectType - Object type token.
parameters - URL parameters to include in the API call (optional).
Returns:
An instance of type objectType which contains the requested objects' data.
See Also:
FacebookClient.executeMultiquery(java.util.Map, java.lang.Class, com.restfb.Parameter[])

executeQuery

public <T> List<T> executeQuery(String query,
                                Class<T> objectType,
                                Parameter... parameters)
Description copied from interface: FacebookClient
Executes an FQL query, mapping the resultset to a List of instances of objectType.

Specified by:
executeQuery in interface FacebookClient
Type Parameters:
T - Java type to map to.
Parameters:
query - The FQL query to execute, e.g. "SELECT name FROM user WHERE uid=220439 or uid=7901103".
objectType - Resultset object type token.
parameters - URL parameters to include in the API call (optional).
Returns:
A list of instances of objectType which map to the query results.
See Also:
FacebookClient.executeQuery(java.lang.String, java.lang.Class, com.restfb.Parameter[])

convertSessionKeysToAccessTokens

public List<FacebookClient.AccessToken> convertSessionKeysToAccessTokens(String appId,
                                                                         String secretKey,
                                                                         String... sessionKeys)
Description copied from interface: FacebookClient
Converts an arbitrary number of sessionKeys to OAuth access tokens.

See the Facebook Platform Upgrade Guide for details on how this process works and why you should convert your application's session keys if you haven't already.

Specified by:
convertSessionKeysToAccessTokens in interface FacebookClient
Parameters:
appId - A Facebook application ID.
secretKey - A Facebook application secret key.
sessionKeys - The Old REST API session keys to be converted to OAuth access tokens.
Returns:
A list of access tokens ordered to correspond to the sessionKeys argument list.
See Also:
FacebookClient.convertSessionKeysToAccessTokens(java.lang.String, java.lang.String, java.lang.String[])


Copyright © 2010-2011. All Rights Reserved.