Package 

Class GraphRequest


  • 
    public final class GraphRequest
    
                        

    A single request to be sent to the Facebook Platform through the Graph API. The Request class provides functionality relating to serializing and deserializing requests and responses, making calls in batches (with a single round-trip to the service) and making calls asynchronously.

    The particular service endpoint that a request targets is determined by a graph path (see the .setGraphPath method).

    A Request can be executed either anonymously or representing an authenticated user. In the former case, no AccessToken needs to be specified, while in the latter, an AccessToken must be provided. If requests are executed in a batch, a Facebook application ID must be associated with the batch, either by setting the application ID in the AndroidManifest.xml or via FacebookSdk or by calling the .setDefaultBatchApplicationId method.

    After completion of a request, the AccessToken, if not null and taken from AccessTokenManager, will be checked to determine if its Facebook access token needs to be extended; if so, a request to extend it will be issued in the background.

    • Constructor Detail

      • GraphRequest

        GraphRequest(AccessToken accessToken, String graphPath, Bundle parameters, HttpMethod httpMethod, GraphRequest.Callback callback, String version)
        Constructs a request with a specific access token, graph path, parameters, and HTTP method.
        Parameters:
        accessToken - the access token to use, or null
        graphPath - the graph path to retrieve, create, or delete
        parameters - additional parameters to pass along with the Graph API request; parameters must be Strings, Numbers, Bitmaps, Dates, or Byte arrays.
        httpMethod - the HttpMethod to use for the request, or null for default (HttpMethod.
        callback - a callback that will be called when the request is completed to handle success or error conditions
        version - the version of the Graph API
      • GraphRequest

        GraphRequest(AccessToken accessToken, String graphPath, Bundle parameters, HttpMethod httpMethod, GraphRequest.Callback callback)
        Constructs a request with a specific access token, graph path, parameters, and HTTP method.
        Parameters:
        accessToken - the access token to use, or null
        graphPath - the graph path to retrieve, create, or delete
        parameters - additional parameters to pass along with the Graph API request; parameters must be Strings, Numbers, Bitmaps, Dates, or Byte arrays.
        httpMethod - the HttpMethod to use for the request, or null for default (HttpMethod.
        callback - a callback that will be called when the request is completed to handle success or error conditions
      • GraphRequest

        GraphRequest(AccessToken accessToken, String graphPath, Bundle parameters, HttpMethod httpMethod)
        Constructs a request with a specific access token, graph path, parameters, and HTTP method.
        Parameters:
        accessToken - the access token to use, or null
        graphPath - the graph path to retrieve, create, or delete
        parameters - additional parameters to pass along with the Graph API request; parameters must be Strings, Numbers, Bitmaps, Dates, or Byte arrays.
        httpMethod - the HttpMethod to use for the request, or null for default (HttpMethod.
      • GraphRequest

        GraphRequest(AccessToken accessToken, String graphPath, Bundle parameters)
        Constructs a request with a specific access token, graph path, parameters, and HTTP method.
        Parameters:
        accessToken - the access token to use, or null
        graphPath - the graph path to retrieve, create, or delete
        parameters - additional parameters to pass along with the Graph API request; parameters must be Strings, Numbers, Bitmaps, Dates, or Byte arrays.
      • GraphRequest

        GraphRequest(AccessToken accessToken, String graphPath)
        Constructs a request with a specific access token, graph path, parameters, and HTTP method.
        Parameters:
        accessToken - the access token to use, or null
        graphPath - the graph path to retrieve, create, or delete
      • GraphRequest

        GraphRequest(AccessToken accessToken)
        Constructs a request with a specific access token, graph path, parameters, and HTTP method.
        Parameters:
        accessToken - the access token to use, or null
      • GraphRequest

        GraphRequest()
        Constructs a request with a specific access token, graph path, parameters, and HTTP method.
    • Method Detail

      • getAccessToken

         final AccessToken getAccessToken()

        The access token associated with this request. Null if none has been specified.

      • setAccessToken

         final Unit setAccessToken(AccessToken accessToken)

        The access token associated with this request. Null if none has been specified.

      • getGraphPath

         final String getGraphPath()

        The graph path of this request, if any. Null if there is none.

      • setGraphPath

         final Unit setGraphPath(String graphPath)

        The graph path of this request, if any. Null if there is none.

      • getGraphObject

         final JSONObject getGraphObject()

        The GraphObject, if any, associated with this request. Null if there is none. This is meaningful only for POST requests.

      • setGraphObject

         final Unit setGraphObject(JSONObject graphObject)

        The GraphObject, if any, associated with this request. Null if there is none. This is meaningful only for POST requests.

      • getBatchEntryName

         final String getBatchEntryName()

        The name of this requests entry in a batched request. Null if none has been specified. This value is only used if this request is submitted as part of a batched request. It can be used to specified dependencies between requests. See Batch Requests in the Graph API documentation for more details.

        It must be unique within a particular batch of requests.

      • setBatchEntryName

         final Unit setBatchEntryName(String batchEntryName)

        The name of this requests entry in a batched request. Null if none has been specified. This value is only used if this request is submitted as part of a batched request. It can be used to specified dependencies between requests. See Batch Requests in the Graph API documentation for more details.

        It must be unique within a particular batch of requests.

      • getBatchEntryDependsOn

         final String getBatchEntryDependsOn()

        The name of the request that this request entry explicitly depends on in a batched request.

        This value is only used if this request is submitted as part of a batched request. It can be used to specified dependencies between requests. See Batch Requests in the Graph API documentation for more details.

      • setBatchEntryDependsOn

         final Unit setBatchEntryDependsOn(String batchEntryDependsOn)

        The name of the request that this request entry explicitly depends on in a batched request.

        This value is only used if this request is submitted as part of a batched request. It can be used to specified dependencies between requests. See Batch Requests in the Graph API documentation for more details.

      • getBatchEntryOmitResultOnSuccess

         final Boolean getBatchEntryOmitResultOnSuccess()

        Whether or not this batch entry will return a response if it is successful. Only applies if another request entry in the batch specifies this entry as a dependency. Null if none has been specified See Batch Requests in the Graph API documentation for more details.

      • setBatchEntryOmitResultOnSuccess

         final Unit setBatchEntryOmitResultOnSuccess(Boolean batchEntryOmitResultOnSuccess)

        Whether or not this batch entry will return a response if it is successful. Only applies if another request entry in the batch specifies this entry as a dependency. Null if none has been specified See Batch Requests in the Graph API documentation for more details.

      • getTag

         final Object getTag()

        The tag on the request; this is an application-defined object that can be used to distinguish between different requests. Its value has no effect on the execution of the request.

      • setTag

         final Unit setTag(Object tag)

        The tag on the request; this is an application-defined object that can be used to distinguish between different requests. Its value has no effect on the execution of the request.

      • getVersion

         final String getVersion()

        The version of the API that this request will use. By default this is the current API at the time the SDK is released. Only use this if you need to explicitly override.

      • setVersion

         final Unit setVersion(String version)

        The version of the API that this request will use. By default this is the current API at the time the SDK is released. Only use this if you need to explicitly override.

      • executeAndWait

         final GraphResponse executeAndWait()

        Executes this request on the current thread and blocks while waiting for the response.

        This should only be called if you have transitioned off the UI thread.

      • executeAsync

         final GraphRequestAsyncTask executeAsync()

        Executes the request asynchronously. This function will return immediately, and the request will be processed on a separate thread. In order to process result of a request, or determine whether a request succeeded or failed, a callback must be specified (see the .setCallback method).

        This should only be called from the UI thread.

      • toString

         String toString()

        Returns a string representation of this Request, useful for debugging.