Package com.restfb

Schnittstelle FacebookClient

Alle bekannten Implementierungsklassen:
DefaultFacebookClient

public interface FacebookClient
Specifies how a Facebook Graph API client must operate.

If you'd like to...

You may also perform some common access token operations. If you'd like to...

Autor:
Mark Allen, Scott Hernandez, Mattia Tommasone, Chris Petersen, Josef Gierbl, Broc Seib
  • Methodendetails

    • 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.
      Typparameter:
      T - Java type to map to.
      Parameter:
      object - ID of the object to fetch, e.g. "me".
      objectType - Object type token.
      parameters - URL parameters to include in the API call (optional).
      Gibt zurück:
      An instance of type objectType which contains the requested object's data.
      Löst aus:
      FacebookException - If an error occurs while performing the API call.
    • createClientWithAccessToken

      creates a new FacebookClient from a old one. App secret and and api version are taken from the original client.
      Parameter:
      accessToken - this accesstoken is used for the new client
      Gibt zurück:
      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.

      Typparameter:
      T - Java type to map to.
      Parameter:
      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).
      Gibt zurück:
      An instance of type objectType which contains the requested objects' data.
      Löst aus:
      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.
      Typparameter:
      T - Java type to map to.
      Parameter:
      connection - The name of the connection, e.g. "me/feed".
      connectionType - Connection type token.
      parameters - URL parameters to include in the API call (optional).
      Gibt zurück:
      An instance of type connectionType which contains the requested Connection's data.
      Löst aus:
      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.
      Typparameter:
      T - Java type to map to.
      Parameter:
      connectionPageUrl - The URL of the connection page to fetch, usually retrieved via Connection.getPreviousPageUrl() or Connection.getNextPageUrl().
      connectionType - Connection type token.
      Gibt zurück:
      An instance of type connectionType which contains the requested Connection's data.
      Löst aus:
      FacebookException - If an error occurs while performing the API call.
    • executeBatch

      Executes operations as a batch using the Batch API.
      Parameter:
      batchRequests - The operations to execute.
      Gibt zurück:
      The execution results in the order in which the requests were specified.
    • executeBatch

      Executes operations as a batch using the Batch API.
      Parameter:
      batchRequests - The operations to execute.
      Gibt zurück:
      The execution results in the order in which the requests were specified.
    • executeBatch

      List<BatchResponse> executeBatch(List<BatchRequest> batchRequests, List<BinaryAttachment> binaryAttachments)
      Executes operations as a batch with binary attachments using the Batch API.
      Parameter:
      batchRequests - The operations to execute.
      binaryAttachments - Binary attachments referenced by the batch requests.
      Gibt zurück:
      The execution results in the order in which the requests were specified.
      Seit:
      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.
      Typparameter:
      T - Java type to map to.
      Parameter:
      connection - The Connection to publish to.
      objectType - Object type token.
      parameters - URL parameters to include in the API call.
      Gibt zurück:
      An instance of type objectType which contains the Facebook response to your publish request.
      Löst aus:
      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.
      Typparameter:
      T - Java type to map to.
      Parameter:
      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.
      Gibt zurück:
      An instance of type objectType which contains the Facebook response to your publish request.
      Löst aus:
      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.
      Typparameter:
      T - Java type to map to.
      Parameter:
      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.
      Gibt zurück:
      An instance of type objectType which contains the Facebook response to your publish request.
      Löst aus:
      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.
      Typparameter:
      T - Java type to map to.
      Parameter:
      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.
      Gibt zurück:
      An instance of type objectType which contains the Facebook response to your publish request.
      Löst aus:
      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.
      Parameter:
      object - The ID of the object to delete.
      parameters - URL parameters to include in the API call.
      Gibt zurück:
      true if Facebook indicated that the object was successfully deleted, false otherwise.
      Löst aus:
      FacebookException - If an error occurred while attempting to delete the object.
    • convertSessionKeysToAccessTokens

      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.

      Parameter:
      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.
      Gibt zurück:
      A list of access tokens ordered to correspond to the sessionKeys argument list.
      Löst aus:
      FacebookException - If an error occurs while attempting to convert the session keys to API keys.
      Seit:
      1.6
    • obtainUserAccessToken

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

      Parameter:
      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.
      Gibt zurück:
      The access token for the user identified by appId, appSecret, redirectUri and verificationCode.
      Löst aus:
      FacebookException - If an error occurs while attempting to obtain an access token.
      Seit:
      1.8.0
    • obtainAppAccessToken

      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.

      Parameter:
      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.
      Gibt zurück:
      The access token for the application identified by appId and appSecret.
      Löst aus:
      FacebookException - If an error occurs while attempting to obtain an access token.
      Seit:
      1.6.10
    • obtainExtendedAccessToken

      Obtains an extended access token for the given existing, non-expired, short-lived access_token.

      See Facebook's extend access token documentation.

      Parameter:
      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.
      Gibt zurück:
      An extended access token for the given accessToken.
      Löst aus:
      FacebookException - If an error occurs while attempting to obtain an extended access token.
      Seit:
      1.6.10
    • obtainAppSecretProof

      String obtainAppSecretProof(String accessToken, String appSecret)
      Generates an appsecret_proof value.

      See Facebook's 'securing requests' documentation for more info.

      Parameter:
      accessToken - The access token required to generate the appsecret_proof value.
      appSecret - The secret for the app for which you'd like to generate the appsecret_proof value.
      Gibt zurück:
      A hex-encoded SHA256 hash as a String.
      Löst aus:
      IllegalStateException - If creating the appsecret_proof fails.
      Seit:
      1.6.13
    • obtainExtendedAccessToken

      Convenience method which invokes obtainExtendedAccessToken(String, String, String) with the current access token.
      Parameter:
      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.
      Gibt zurück:
      An extended access token for the given accessToken.
      Löst aus:
      FacebookException - If an error occurs while attempting to obtain an extended access token.
      IllegalStateException - If this instance was not constructed with an access token.
      Seit:
      1.6.10
    • parseSignedRequest

      <T> T parseSignedRequest(String signedRequest, String appSecret, Class<T> objectType)
      Parses a signed request and verifies it against your App Secret.

      See Facebook's signed request documentation.

      Typparameter:
      T - class of objectType
      Parameter:
      signedRequest - The signed request to parse.
      appSecret - The secret for the app that can read this signed request.
      objectType - Object type token.
      Gibt zurück:
      An instance of type objectType which contains the decoded object embedded within signedRequest.
      Löst aus:
      FacebookSignedRequestParsingException - If an error occurs while trying to process signedRequest.
      FacebookSignedRequestVerificationException - If signedRequest fails verification against appSecret.
      Seit:
      1.6.13
    • fetchDeviceCode

      Method to initialize the device access token generation. You receive a DeviceCode instance and have to show the user the DeviceCode.getVerificationUri() and the DeviceCode.getUserCode(). The user have to enter the user code at the verification url. Save the DeviceCode.getCode() to use it later, when polling Facebook with the obtainDeviceAccessToken(java.lang.String) method.
      Parameter:
      scope - List of Permissions to request from the person using your app.
      Gibt zurück:
      Instance of DeviceCode including the information to obtain the Device access token
    • obtainDeviceAccessToken

      Method to poll Facebook and fetch the Device Access Token. You have to use this method to check if the user confirms the authorization. FacebookOAuthException can be thrown if the authorization is declined or still pending.
      Parameter:
      code - The device
      Gibt zurück:
      An extended access token for the given FacebookClient.AccessToken.
      Löst aus:
      FacebookDeviceTokenCodeExpiredException - the DeviceCode.getCode() is expired, please fetch a new DeviceCode.
      FacebookDeviceTokenPendingException - the user has not finished the authorisation process, yet. Please poll again later.
      FacebookDeviceTokenDeclinedException - the user declined the authorisation. You have to handle this problem.
      FacebookDeviceTokenSlowdownException - you tried too often to fetch the device access token. You have to use a larger interval
      Seit:
      1.12.0
    • debugToken

      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

      Parameter:
      inputToken - The Access Token to debug.
      Gibt zurück:
      A JsonObject containing the debug information for the accessToken.
      Seit:
      1.6.13
    • getJsonMapper

      Gets the JsonMapper used to convert Facebook JSON to Java objects.
      Gibt zurück:
      The JsonMapper used to convert Facebook JSON to Java objects.
      Seit:
      1.6.7
    • getWebRequestor

      Gets the WebRequestor used to talk to the Facebook API endpoints.
      Gibt zurück:
      The WebRequestor used to talk to the Facebook API endpoints.
      Seit:
      1.6.7
    • getLogoutUrl

      generates an logout url
      Parameter:
      next - may be null, url the webpage should redirect after logout
      Gibt zurück:
      the logout url
      Seit:
      1.9.0
    • getLoginDialogUrl

      String getLoginDialogUrl(String appId, String redirectUri, ScopeBuilder scope, Parameter... additionalParameters)
      generates the login dialog url
      Parameter:
      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
      Gibt zurück:
      the login dialog url
      Seit:
      1.9.0