Package com.restfb

Interface FacebookClient

    • Method Detail

      • fetchObject

        <T> T fetchObject​(String object,
                          Class<T> objectType,
                          Parameter... parameters)
        Fetches a single Graph API object, mapping the result to an instance of objectType.
        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.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • createClientWithAccessToken

        FacebookClient createClientWithAccessToken​(String accessToken)
        creates a new FacebookClient from a old one. App secret and and api version are taken from the original client.
        Parameters:
        accessToken - this accesstoken is used for the new client
        Returns:
        a new Facebookclient
      • fetchObjects

        <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.

        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.

        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.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • fetchConnection

        <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.
        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.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • fetchConnectionPage

        <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.
        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.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • executeBatch

        List<BatchResponseexecuteBatch​(BatchRequest... batchRequests)
        Executes operations as a batch using the Batch API.
        Parameters:
        batchRequests - The operations to execute.
        Returns:
        The execution results in the order in which the requests were specified.
      • executeBatch

        List<BatchResponseexecuteBatch​(List<BatchRequest> batchRequests)
        Executes operations as a batch using the Batch API.
        Parameters:
        batchRequests - The operations to execute.
        Returns:
        The execution results in the order in which the requests were specified.
      • executeBatch

        List<BatchResponseexecuteBatch​(List<BatchRequest> batchRequests,
                                         List<BinaryAttachment> binaryAttachments)
        Executes operations as a batch with binary attachments using the Batch API.
        Parameters:
        batchRequests - The operations to execute.
        binaryAttachments - Binary attachments referenced by the batch requests.
        Returns:
        The execution results in the order in which the requests were specified.
        Since:
        1.6.5
      • publish

        <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.
        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.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • publish

        <T> T publish​(String connection,
                      Class<T> objectType,
                      List<BinaryAttachment> binaryAttachments,
                      Parameter... parameters)
        Performs a Graph API publish operation on the given connection and includes some files - photos, for example - in the publish request, and mapping the result to an instance of objectType.
        Type Parameters:
        T - Java type to map to.
        Parameters:
        connection - The Connection to publish to.
        objectType - Object type token.
        binaryAttachments - The files to include in the publish request.
        parameters - URL parameters to include in the API call.
        Returns:
        An instance of type objectType which contains the Facebook response to your publish request.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • publish

        <T> T publish​(String connection,
                      Class<T> objectType,
                      BinaryAttachment 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.
        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.
        parameters - URL parameters to include in the API call.
        Returns:
        An instance of type objectType which contains the Facebook response to your publish request.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • publish

        <T> T publish​(String connection,
                      Class<T> objectType,
                      Body body,
                      Parameter... parameters)
        Performs a Graph API publish operation on the given connection and includes special body in the publish request, and mapping the result to an instance of objectType.
        Type Parameters:
        T - Java type to map to.
        Parameters:
        connection - The Connection to publish to.
        objectType - Object type token.
        body - The body used in the POST request.
        parameters - URL parameters to include in the API call.
        Returns:
        An instance of type objectType which contains the Facebook response to your publish request.
        Throws:
        FacebookException - If an error occurs while performing the API call.
      • deleteObject

        boolean deleteObject​(String object,
                             Parameter... parameters)
        Performs a Graph API delete operation on the given object.
        Parameters:
        object - The ID of the object to delete.
        parameters - URL parameters to include in the API call.
        Returns:
        true if Facebook indicated that the object was successfully deleted, false otherwise.
        Throws:
        FacebookException - If an error occurred while attempting to delete the object.
      • convertSessionKeysToAccessTokens

        List<AccessTokenconvertSessionKeysToAccessTokens​(String appId,
                                                           String secretKey,
                                                           String... sessionKeys)
        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.

        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.
        Throws:
        FacebookException - If an error occurs while attempting to convert the session keys to API keys.
        Since:
        1.6
      • obtainUserAccessToken

        AccessToken obtainUserAccessToken​(String appId,
                                          String appSecret,
                                          String redirectUri,
                                          String verificationCode)
        Obtains an access token which can be used to perform Graph API operations on behalf of a user.

        See Access Tokens.

        Parameters:
        appId - The ID of the app for which you'd like to obtain an access token.
        appSecret - The secret for the app for which you'd like to obtain an access token.
        redirectUri - The redirect URI which was used to obtain the verificationCode.
        verificationCode - The verification code in the Graph API callback to the redirect URI.
        Returns:
        The access token for the user identified by appId, appSecret, redirectUri and verificationCode.
        Throws:
        FacebookException - If an error occurs while attempting to obtain an access token.
        Since:
        1.8.0
      • obtainAppAccessToken

        AccessToken obtainAppAccessToken​(String appId,
                                         String appSecret)
        Obtains an access token which can be used to perform Graph API operations on behalf of an application instead of a user.

        See Facebook's authenticating as an app documentation.

        Parameters:
        appId - The ID of the app for which you'd like to obtain an access token.
        appSecret - The secret for the app for which you'd like to obtain an access token.
        Returns:
        The access token for the application identified by appId and appSecret.
        Throws:
        FacebookException - If an error occurs while attempting to obtain an access token.
        Since:
        1.6.10
      • obtainExtendedAccessToken

        AccessToken obtainExtendedAccessToken​(String appId,
                                              String appSecret,
                                              String accessToken)
        Obtains an extended access token for the given existing, non-expired, short-lived access_token.

        See Facebook's extend access token documentation.

        Parameters:
        appId - The ID of the app for which you'd like to obtain an extended access token.
        appSecret - The secret for the app for which you'd like to obtain an extended access token.
        accessToken - The non-expired, short-lived access token to extend.
        Returns:
        An extended access token for the given accessToken.
        Throws:
        FacebookException - If an error occurs while attempting to obtain an extended access token.
        Since:
        1.6.10
      • debugToken

        DebugTokenInfo debugToken​(String inputToken)

        When working with access tokens, you may need to check what information is associated with them, such as its user or expiry. To get this information you can use the debug tool in the developer site, or you can use this function.

        You must instantiate your FacebookClient using your App Access Token, or a valid User Access Token from a developer of the app.

        Note that if your app is set to Native/Desktop in the Advanced settings of your App Dashboard, the underlying GraphAPI endpoint will not work with your app token unless you change the "App Secret in Client" setting to NO. If you do not see this setting, make sure your "App Type" is set to Native/Desktop and then press the save button at the bottom of the page. This will not affect apps set to Web.

        The response of the API call is a JSON array containing data and a map of fields. For example:

         
         {
             "data": {
                 "app_id": 138483919580948, 
                 "application": "Social Cafe", 
                 "expires_at": 1352419328, 
                 "is_valid": true, 
                 "issued_at": 1347235328, 
                 "metadata": {
                     "sso": "iphone-safari"
                 }, 
                 "scopes": [
                     "email", 
                     "publish_actions"
                 ], 
                 "user_id": 1207059
             }
         }
         
         

        Note that the issued_at field is not returned for short-lived access tokens.

        See Debugging an Access Token

        Parameters:
        inputToken - The Access Token to debug.
        Returns:
        A JsonObject containing the debug information for the accessToken.
        Since:
        1.6.13
      • getJsonMapper

        JsonMapper getJsonMapper()
        Gets the JsonMapper used to convert Facebook JSON to Java objects.
        Returns:
        The JsonMapper used to convert Facebook JSON to Java objects.
        Since:
        1.6.7
      • getWebRequestor

        WebRequestor getWebRequestor()
        Gets the WebRequestor used to talk to the Facebook API endpoints.
        Returns:
        The WebRequestor used to talk to the Facebook API endpoints.
        Since:
        1.6.7
      • getLogoutUrl

        String getLogoutUrl​(String next)
        generates an logout url
        Parameters:
        next - may be null, url the webpage should redirect after logout
        Returns:
        the logout url
        Since:
        1.9.0
      • getLoginDialogUrl

        String getLoginDialogUrl​(String appId,
                                 String redirectUri,
                                 ScopeBuilder scope,
                                 Parameter... additionalParameters)
        generates the login dialog url
        Parameters:
        appId - The ID of your app, found in your app's dashboard.
        redirectUri - The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set to https://www.facebook.com/connect/login_success.html.
        scope - List of Permissions to request from the person using your app.
        additionalParameters - List of additional parameters
        Returns:
        the login dialog url
        Since:
        1.9.0