Android SDK Version


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.
Nested Class Summary
Modifier and TypeClassDescription
public classGraphRequest.Companion
public interfaceGraphRequest.Callback
Specifies the interface that consumers of the Request class can implement in order to be notified when a particular request completes, either successfully or with an error.
public interfaceGraphRequest.OnProgressCallback
Specifies the interface that consumers of the Request class can implement in order to be notified when a progress is made on a particular request. The frequency of the callbacks can be controlled using FacebookSdk.setOnProgressThreshold
public interfaceGraphRequest.GraphJSONArrayCallback
Callback for requests that result in an array of JSONObjects.
public interfaceGraphRequest.GraphJSONObjectCallback
Callback for requests that result in a JSONObject.
public final classGraphRequest.ParcelableResourceWithMimeType
Constructor Summary
ConstructorDescription
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.
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.
GraphRequest(AccessToken accessToken, String graphPath, Bundle parameters, HttpMethod httpMethod)Constructs a request with a specific access token, graph path, parameters, and HTTP method.
GraphRequest(AccessToken accessToken, String graphPath, Bundle parameters)Constructs a request with a specific access token, graph path, parameters, and HTTP method.
GraphRequest(AccessToken accessToken, String graphPath)Constructs a request with a specific access token, graph path, parameters, and HTTP method.
GraphRequest(AccessToken accessToken)Constructs a request with a specific access token, graph path, parameters, and HTTP method.
GraphRequest()Constructs a request with a specific access token, graph path, parameters, and HTTP method.
Method Summary
Modifier and TypeMethodDescription
final AccessTokengetAccessToken() The access token associated with this request.
final UnitsetAccessToken(AccessToken accessToken) The access token associated with this request.
final StringgetGraphPath() The graph path of this request, if any.
final UnitsetGraphPath(String graphPath) The graph path of this request, if any.
final JSONObjectgetGraphObject() The GraphObject, if any, associated with this request.
final UnitsetGraphObject(JSONObject graphObject) The GraphObject, if any, associated with this request.
final StringgetBatchEntryName() The name of this requests entry in a batched request.
final UnitsetBatchEntryName(String batchEntryName) The name of this requests entry in a batched request.
final StringgetBatchEntryDependsOn() The name of the request that this request entry explicitly depends on in a batched request.
final UnitsetBatchEntryDependsOn(String batchEntryDependsOn) The name of the request that this request entry explicitly depends on in a batched request.
final BooleangetBatchEntryOmitResultOnSuccess() Whether or not this batch entry will return a response if it is successful.
final UnitsetBatchEntryOmitResultOnSuccess(Boolean batchEntryOmitResultOnSuccess) Whether or not this batch entry will return a response if it is successful.
final BundlegetParameters() The parameters for this request.
final UnitsetParameters(Bundle parameters) The parameters for this request.
final ObjectgetTag() The tag on the request; this is an application-defined object that can be used to distinguish between different requests.
final UnitsetTag(Object tag) The tag on the request; this is an application-defined object that can be used to distinguish between different requests.
final StringgetVersion() The version of the API that this request will use.
final UnitsetVersion(String version) The version of the API that this request will use.
final GraphRequest.CallbackgetCallback() The callback which will be called when the request finishes.
final UnitsetCallback(GraphRequest.Callback callback)
final HttpMethodgetHttpMethod() The HttpMethod to use for this request.
final UnitsetHttpMethod(HttpMethod httpMethod)
final StringgetRelativeUrlForBatchedRequest()
final StringgetUrlForSingleRequest()
final UnitsetSkipClientToken(Boolean skipClientToken) This is an internal function that is not meant to be used by developers.
final UnitsetForceApplicationRequest(Boolean forceOverride) This is an internal function that is not meant to be used by developers.
final GraphResponseexecuteAndWait() Executes this request on the current thread and blocks while waiting for the response.
final GraphRequestAsyncTaskexecuteAsync() Executes the request asynchronously.
StringtoString() Returns a string representation of this Request, useful for debugging.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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 AccessTokengetAccessToken()
The access token associated with this request. Null if none has been specified.

setAccessToken

 final UnitsetAccessToken(AccessToken accessToken)
The access token associated with this request. Null if none has been specified.

getGraphPath

 final StringgetGraphPath()
The graph path of this request, if any. Null if there is none.

setGraphPath

 final UnitsetGraphPath(String graphPath)
The graph path of this request, if any. Null if there is none.

getGraphObject

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

setGraphObject

 final UnitsetGraphObject(JSONObject graphObject)
The GraphObject, if any, associated with this request. Null if there is none. This is meaningful only for POST requests.

getBatchEntryName

 final StringgetBatchEntryName()
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 UnitsetBatchEntryName(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 StringgetBatchEntryDependsOn()
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 UnitsetBatchEntryDependsOn(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 BooleangetBatchEntryOmitResultOnSuccess()
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 UnitsetBatchEntryOmitResultOnSuccess(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.

getParameters

 final BundlegetParameters()
The parameters for this request.

setParameters

 final UnitsetParameters(Bundle parameters)
The parameters for this request.

getTag

 final ObjectgetTag()
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 UnitsetTag(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 StringgetVersion()
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 UnitsetVersion(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.

getCallback

 final GraphRequest.CallbackgetCallback()
The callback which will be called when the request finishes.

setCallback

 final UnitsetCallback(GraphRequest.Callback callback)

getHttpMethod

 final HttpMethodgetHttpMethod()
The HttpMethod to use for this request. Assign null for default (HttpMethod.GET)

setHttpMethod

 final UnitsetHttpMethod(HttpMethod httpMethod)

getRelativeUrlForBatchedRequest

 final StringgetRelativeUrlForBatchedRequest()

getUrlForSingleRequest

 final StringgetUrlForSingleRequest()

setSkipClientToken

@Deprecated(message = Starting in v13, the SDK will require a client token to be set before making GraphAPI calls.) final UnitsetSkipClientToken(Boolean skipClientToken)
This is an internal function that is not meant to be used by developers.

setForceApplicationRequest

 final UnitsetForceApplicationRequest(Boolean forceOverride)
This is an internal function that is not meant to be used by developers.

executeAndWait

 final GraphResponseexecuteAndWait()
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 GraphRequestAsyncTaskexecuteAsync()
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

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