The FBRequest
object is used to setup and manage requests to the Facebook Graph API.
This class provides helper methods that simplify the connection and response handling.
An FBSession object is required for all authenticated uses of FBRequest
.
Requests that do not require an unauthenticated user are also supported and
do not require an FBSession object to be passed in.
An instance of FBRequest
represents the arguments and setup for a connection
to Facebook. After creating an FBRequest
object it can be used to setup a
connection to Facebook through the FBRequestConnection object. The
FBRequestConnection object is created to manage a single connection. To
cancel a connection use the instance method in the FBRequestConnection class.
An FBRequest
object may be reused to issue multiple connections to Facebook.
However each FBRequestConnection instance will manage one connection.
Class and instance methods prefixed with start can be used to perform the request setup and initiate the connection in a single call.
Inherits from: | NSObject |
Declared in: | FBRequest.h |
graphObject
The graph object to post with the request.
@property (nonatomic,
retain) id<FBGraphObject> graphObject;
May be used to read the graph object that was automatically set during the object initiliazation. Make any required modifications prior to sending the request.
FBRequest.h
graphPath
The Graph API endpoint to use for the request, for example "me".
@property (nonatomic,
copy) NSString *graphPath;
May be used to read the Graph API endpoint that was automatically set during the object initiliazation. Make any required modifications prior to sending the request.
FBRequest.h
HTTPMethod
The HTTPMethod to use for the request, for example "GET" or "POST".
@property (nonatomic,
copy) NSString *HTTPMethod;
May be used to read the HTTP method that was automatically set during the object initiliazation. Make any required modifications prior to sending the request.
FBRequest.h
parameters
The parameters for the request.
@property (nonatomic,
retain,
readonly) NSMutableDictionary *parameters;
May be used to read the parameters that were automatically set during the object initiliazation. Make any required modifications prior to sending the request.
NSString
parameters are used to generate URL parameter values or JSON
parameters. NSData
and UIImage
parameters are added as attachments
to the HTTP body and referenced by name in the URL and/or JSON.
FBRequest.h
session
The FBSession session object to use for the request.
@property (nonatomic,
retain) FBSession *session;
May be used to read the session that was automatically set during the object initiliazation. Make any required modifications prior to sending the request.
FBRequest.h
requestForCustomAudienceThirdPartyID:
Creates a request representing the Graph API call to retrieve a Custom Audience "thirdy party ID" for the app's Facebook user. Callers will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with, and then use the resultant Custom Audience to target ads.
Parâmetro | Descrição |
---|---|
session | The FBSession to use to establish the user's identity for users logged into Facebook through this app.
If |
+ (FBRequest *)
requestForCustomAudienceThirdPartyID:(FBSession *)session;
This method will throw an exception if [FBSettings defaultAppID]
is nil
. The appID won't be nil when the pList
includes the appID, or if it's explicitly set.
The JSON in the request's response will include an "custom_audience_third_party_id" key/value pair, with the value being the ID retrieved. This ID is an encrypted encoding of the Facebook user's ID and the invoking Facebook app ID. Multiple calls with the same user will return different IDs, thus these IDs cannot be used to correlate behavior across devices or applications, and are only meaningful when sent back to Facebook for creating Custom Audiences.
The ID retrieved represents the Facebook user identified in the following way: if the specified session (or activeSession if the specified
session is nil
) is open, the ID will represent the user associated with the activeSession; otherwise the ID will represent the user logged into the
native Facebook app on the device. If there is no native Facebook app, no one is logged into it, or the user has opted out
at the iOS level from ad tracking, then a nil
ID will be returned.
This method returns nil
if either the user has opted-out (via iOS) from Ad Tracking, the app itself has limited event usage
via the [FBAppEvents setLimitEventUsage]
flag, or a specific Facebook user cannot be identified.
FBRequest.h
requestForDeleteObject:
Creates request representing a DELETE to a object.
Parâmetro | Descrição |
---|---|
object | This can be an NSString, NSNumber or NSDictionary representing an object to delete |
+ (FBRequest *)
requestForDeleteObject:(id)object;
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForGraphPath:
Returns a newly initialized request object that can be used to make a Graph API call for the active session.
Parâmetro | Descrição |
---|---|
graphPath | The Graph API endpoint to use for the request, for example "me". |
+ (FBRequest *)
requestForGraphPath:(NSString *)graphPath;
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForMe
Creates a request representing a Graph API call to the "me" endpoint, using the active session.
+ (FBRequest *)
requestForMe;
Simplifies preparing a request to retrieve the user's identity.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
A successful Graph API call will return an FBGraphUser object representing the user's identity.
Note you may change the session property after construction if a session other than the active session is preferred.
FBRequest.h
requestForMyFriends
Creates a request representing a Graph API call to the "me/friends" endpoint using the active session.
+ (FBRequest *)
requestForMyFriends;
Simplifies preparing a request to retrieve the user's friends.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
A successful Graph API call will return an array of FBGraphUser objects representing the user's friends.
FBRequest.h
requestForPlacesSearchAtCoordinate:radiusInMeters:resultsLimit:searchText:
Creates a request representing a Graph API call to the "search" endpoint for a given location using the active session.
Parâmetro | Descrição |
---|---|
coordinate | The search coordinates. |
radius | The search radius in meters. |
limit | The maxiumum number of results to return. It is possible to receive fewer than this because of the radius and because of server limits. |
searchText | The text to use in the query to narrow the set of places returned. |
+ (FBRequest *)
requestForPlacesSearchAtCoordinate | |
CLLocationCoordinate | |
D | |
coordinate | |
radiusInMeters: | (NSInteger)radius |
resultsLimit: | (NSInteger)limit |
searchText: | (NSString *)searchText; |
Simplifies preparing a request to search for places near a coordinate.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
A successful Graph API call will return an array of FBGraphPlace objects representing the nearby locations.
FBRequest.h
requestForPostOpenGraphObject:
Returns a newly initialized request object that can be used to create a user owned Open Graph object for the active session.
Parâmetro | Descrição |
---|---|
object | The Open Graph object to create. Some common expected fields include "title", "image", "url", etc. |
+ (FBRequest *)
requestForPostOpenGraphObject:(id<FBOpenGraphObject>)object;
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForPostOpenGraphObjectWithType:title:image:url:description:objectProperties:
Returns a newly initialized request object that can be used to create a user owned Open Graph object for the active session.
Parâmetro | Descrição |
---|---|
type | The fully-specified Open Graph object type (e.g., my_app_namespace:my_object_name) |
title | The title of the Open Graph object. |
image | The link to an image to be associated with the Open Graph object. |
url | The url to be associated with the Open Graph object. |
description | The description to be associated with the object. |
objectProperties | Any additional properties for the Open Graph object. |
+ (FBRequest *)
requestForPostOpenGraphObjectWithType: | (NSString *)type |
title: | (NSString *)title |
image: | (id)image |
url: | (id)url |
description: | (NSString *)description |
objectProperties: | (NSDictionary *)objectProperties; |
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForPostStatusUpdate:
Creates a request representing a status update.
Parâmetro | Descrição |
---|---|
message | The message to post. |
+ (FBRequest *)
requestForPostStatusUpdate:(NSString *)message;
Simplifies preparing a request to post a status update.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForPostStatusUpdate:place:tags:
Creates a request representing a status update.
Parâmetro | Descrição |
---|---|
message | The message to post. |
place | The place to checkin with, or nil. Place may be an fbid or a graph object representing a place. |
tags | Array of friends to tag in the status update, each element may be an fbid or a graph object representing a user. |
+ (FBRequest *)
requestForPostStatusUpdate: | (NSString *)message |
place: | (id)place |
tags: | (id<NSFastEnumeration>)tags; |
Simplifies preparing a request to post a status update.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForPostWithGraphPath:graphObject:
Creates a request representing a POST for a graph object.
Parâmetro | Descrição |
---|---|
graphPath | The Graph API endpoint to use for the request, for example "me". |
graphObject | An object or open graph action to post. |
+ (FBRequest *)
requestForPostWithGraphPath: | (NSString *)graphPath |
graphObject: | (id<FBGraphObject>)graphObject; |
This method is typically used for posting an open graph action. If you are only
posting an open graph object (without an action), consider using requestForPostOpenGraphObject:
FBRequest.h
requestForUpdateOpenGraphObject:
Returns a newly initialized request object that can be used to update a user owned Open Graph object for the active session.
Parâmetro | Descrição |
---|---|
object | The Open Graph object to update the existing object with. |
+ (FBRequest *)
requestForUpdateOpenGraphObject:(id<FBOpenGraphObject>)object;
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForUpdateOpenGraphObjectWithId:title:image:url:description:objectProperties:
Returns a newly initialized request object that can be used to update a user owned Open Graph object for the active session.
Parâmetro | Descrição |
---|---|
objectId | The id of the Open Graph object to update. |
title | The updated title of the Open Graph object. |
image | The updated link to an image to be associated with the Open Graph object. |
url | The updated url to be associated with the Open Graph object. |
description | The updated description of the Open Graph object. |
objectProperties | Any additional properties to update for the Open Graph object. |
+ (FBRequest *)
requestForUpdateOpenGraphObjectWithId: | (id)objectId |
title: | (NSString *)title |
image: | (id)image |
url: | (id)url |
description: | (NSString *)description |
objectProperties: | (NSDictionary *)objectProperties; |
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForUploadPhoto:
Creates a request representing a Graph API call to upload a photo to the app's album using the active session.
Parâmetro | Descrição |
---|---|
photo | A |
+ (FBRequest *)
requestForUploadPhoto:(UIImage *)photo;
Simplifies preparing a request to post a photo.
To post a photo to a specific album, get the FBRequest
returned from this method
call, then modify the request parameters by adding the album ID to an "album" key.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestForUploadStagingResourceWithImage:
Returns a newly initialized request object that can be used to upload an image to create a staging resource. Staging resources allow you to post binary data such as images, in preparation for a post of an open graph object or action which references the image. The URI returned when uploading a staging resource may be passed as the image property for an open graph object or action.
Parâmetro | Descrição |
---|---|
image | A |
+ (FBRequest *)
requestForUploadStagingResourceWithImage:(UIImage *)image;
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
requestWithGraphPath:parameters:HTTPMethod:
Returns a newly initialized request object that can be used to make a Graph API call for the active session.
Parâmetro | Descrição |
---|---|
graphPath | The Graph API endpoint to use for the request, for example "me". |
parameters | The parameters for the request. A value of nil sends only the automatically handled parameters, for example, the access token. The default is nil. |
HTTPMethod | The HTTP method to use for the request. A nil value implies a GET. |
+ (FBRequest *)
requestWithGraphPath: | (NSString *)graphPath |
parameters: | (NSDictionary *)parameters |
HTTPMethod: | (NSString *)HTTPMethod; |
This method simplifies the preparation of a Graph API call.
This method does not initialize an FBRequestConnection object. To initiate the API
call first instantiate an FBRequestConnection object, add the request to this object,
then call the start
method on the connection instance.
FBRequest.h
initForPostWithSession:graphPath:graphObject:
Initialize a FBRequest
object that will do a graph request.
Parâmetro | Descrição |
---|---|
session | The session object representing the identity of the Facebook user making
the request. A nil value indicates a request that requires no token; to
use the active session pass |
graphPath | The Graph API endpoint to use for the request, for example "me". |
graphObject | An object or open graph action to post. |
- (instancetype)
initForPostWithSession: | (FBSession *)session |
graphPath: | (NSString *)graphPath |
graphObject: | (id<FBGraphObject>)graphObject; |
Note that this only sets properties on the FBRequest
.
To send the request, initialize a FBRequestConnection, add this request,
and send [FBRequestConnection start]
. See other methods on this
class for shortcuts to simplify this process.
FBRequest.h
initWithSession:graphPath:
Parâmetro | Descrição |
---|---|
session | The session object representing the identity of the Facebook user making
the request. A nil value indicates a request that requires no token; to
use the active session pass |
graphPath | The Graph API endpoint to use for the request, for example "me". |
- (instancetype)
initWithSession: | (FBSession *)session |
graphPath: | (NSString *)graphPath; |
Calls initWithSession:graphPath:parameters:HTTPMethod:
with default parameters
except for the ones provided to this method.
FBRequest.h
initWithSession:graphPath:parameters:HTTPMethod:
Initializes an FBRequest
object for a Graph API request call.
Parâmetro | Descrição |
---|---|
session | The session object representing the identity of the Facebook user making
the request. A nil value indicates a request that requires no token; to
use the active session pass |
graphPath | The Graph API endpoint to use for the request, for example "me". |
parameters | The parameters for the request. A value of nil sends only the automatically handled parameters, for example, the access token. The default is nil. |
HTTPMethod | The HTTP method to use for the request. The default is value of nil implies a GET. |
- (instancetype)
initWithSession: | (FBSession *)session |
graphPath: | (NSString *)graphPath |
parameters: | (NSDictionary *)parameters |
HTTPMethod: | (NSString *)HTTPMethod; |
Note that this only sets properties on the FBRequest
object.
To send the request, initialize an FBRequestConnection object, add this request,
and send [FBRequestConnection start]
. See other methods on this
class for shortcuts to simplify this process.
FBRequest.h
overrideVersionPartWith:
Overrides the default version for a single request
Parâmetro | Descrição |
---|---|
version | This is a string in the form @"v2.0" which will be used for the version part of an API path |
- (void)
overrideVersionPartWith:(NSString *)version;
The SDK automatically prepends a version part, such as "v2.0" to API paths in order to simplify API versioning for applications. Sometimes it is preferable to explicitly set the version for a request, which can be accomplished in one of two ways. The first is to call this method and set an override version part. The second is approach is to include the version part in the api path, for example @"v2.0/me/friends"
FBRequest.h
startWithCompletionHandler:
Starts a connection to the Facebook API.
Parâmetro | Descrição |
---|---|
handler | The handler block to call when the request completes with a success, error, or cancel action. The handler will be invoked on the main thread. |
- (FBRequestConnection *)
startWithCompletionHandler:(FBRequestHandler)handler;
This is used to start an API call to Facebook and call the block when the request completes with a success, error, or cancel.
FBRequest.h
FBGraphBasePath
FBSDK_EXTER N NSString *const FBGraphBasePath __attribute__((deprecated));
The base URL used for graph requests
FBRequest.h
FBRequestState
Deprecated - do not use in new code.
typedef NSUInteger FBRequestState __attribute__((deprecated));
FBRequestState is retained from earlier versions of the SDK to give existing apps time to remove dependency on this.
FBRequest.h