-
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
Nested Classes Modifier and Type Class Description public class
GraphRequest.Companion
public interface
GraphRequest.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 interface
GraphRequest.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 interface
GraphRequest.GraphJSONArrayCallback
Callback for requests that result in an array of JSONObjects.
public interface
GraphRequest.GraphJSONObjectCallback
Callback for requests that result in a JSONObject.
public final class
GraphRequest.ParcelableResourceWithMimeType
-
Field Summary
Fields Modifier and Type Field Description private AccessToken
accessToken
private String
graphPath
private JSONObject
graphObject
private String
batchEntryName
private String
batchEntryDependsOn
private Boolean
batchEntryOmitResultOnSuccess
private Bundle
parameters
private Object
tag
private String
version
private GraphRequest.Callback
callback
private HttpMethod
httpMethod
private final String
relativeUrlForBatchedRequest
private final String
urlForSingleRequest
-
Constructor Summary
Constructors Constructor Description 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 Type Method Description final AccessToken
getAccessToken()
The access token associated with this request. final Unit
setAccessToken(AccessToken accessToken)
The access token associated with this request. final String
getGraphPath()
The graph path of this request, if any. final Unit
setGraphPath(String graphPath)
The graph path of this request, if any. final JSONObject
getGraphObject()
The GraphObject, if any, associated with this request. final Unit
setGraphObject(JSONObject graphObject)
The GraphObject, if any, associated with this request. final String
getBatchEntryName()
The name of this requests entry in a batched request. final Unit
setBatchEntryName(String batchEntryName)
The name of this requests entry in a batched request. final String
getBatchEntryDependsOn()
The name of the request that this request entry explicitly depends on in a batched request. final Unit
setBatchEntryDependsOn(String batchEntryDependsOn)
The name of the request that this request entry explicitly depends on in a batched request. final Boolean
getBatchEntryOmitResultOnSuccess()
Whether or not this batch entry will return a response if it is successful. final Unit
setBatchEntryOmitResultOnSuccess(Boolean batchEntryOmitResultOnSuccess)
Whether or not this batch entry will return a response if it is successful. final Bundle
getParameters()
The parameters for this request. final Unit
setParameters(Bundle parameters)
The parameters for this request. final Object
getTag()
The tag on the request; this is an application-defined object that can be used to distinguish between different requests. 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. final String
getVersion()
The version of the API that this request will use. final Unit
setVersion(String version)
The version of the API that this request will use. final GraphRequest.Callback
getCallback()
The callback which will be called when the request finishes. final Unit
setCallback(GraphRequest.Callback callback)
final HttpMethod
getHttpMethod()
The HttpMethod to use for this request. final Unit
setHttpMethod(HttpMethod httpMethod)
final String
getRelativeUrlForBatchedRequest()
final String
getUrlForSingleRequest()
final Unit
setForceApplicationRequest(Boolean forceOverride)
This is an internal function that is not meant to be used by developers. final GraphResponse
executeAndWait()
Executes this request on the current thread and blocks while waiting for the response. final GraphRequestAsyncTask
executeAsync()
Executes the request asynchronously. String
toString()
Returns a string representation of this Request, useful for debugging. -
-
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 nullgraphPath
- the graph path to retrieve, create, or deleteparameters
- 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 conditionsversion
- 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 nullgraphPath
- the graph path to retrieve, create, or deleteparameters
- 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 nullgraphPath
- the graph path to retrieve, create, or deleteparameters
- 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 nullgraphPath
- the graph path to retrieve, create, or deleteparameters
- 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 nullgraphPath
- 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.
-
getParameters
final Bundle getParameters()
The parameters for this request.
-
setParameters
final Unit setParameters(Bundle parameters)
The parameters for this request.
-
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.
-
getCallback
final GraphRequest.Callback getCallback()
The callback which will be called when the request finishes.
-
setCallback
final Unit setCallback(GraphRequest.Callback callback)
-
getHttpMethod
final HttpMethod getHttpMethod()
The HttpMethod to use for this request. Assign null for default (HttpMethod.GET)
-
setHttpMethod
final Unit setHttpMethod(HttpMethod httpMethod)
-
getRelativeUrlForBatchedRequest
final String getRelativeUrlForBatchedRequest()
-
getUrlForSingleRequest
final String getUrlForSingleRequest()
-
setForceApplicationRequest
final Unit setForceApplicationRequest(Boolean forceOverride)
This is an internal function that is not meant to be used by developers.
-
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.
-
-
-
-