Mac Developer Library

Developer

Social Framework Reference SLRequest Class Reference

Options
Deployment Target:

On This Page
Language:

SLRequest

The SLRequest object encapsulates the properties of an HTTP request, providing a convenient template for you to make requests. You send a request to a social networking service to perform some operation on behalf of the user or to retrieve user information. More...

Inheritance


Conforms To


Import Statement


import Social @import Social;

Availability


Available in OS X v10.8 and later.
  • Initializes a newly created request object with the specified properties.

    Declaration

    Swift

    init!(forServiceType serviceType: String!, requestMethod requestMethod: SLRequestMethod, URL url: NSURL!, parameters parameters: [NSObject : AnyObject]!) -> SLRequest

    Objective-C

    + (SLRequest *)requestForServiceType:(NSString *)serviceType requestMethod:(SLRequestMethod)requestMethod URL:(NSURL *)url parameters:(NSDictionary *)parameters

    Parameters

    serviceType

    The social networking service type. For possible values, see Service Type Constants.

    requestMethod

    The method to use for this HTTP request. For possible values, see SLRequestMethod.

    url

    The destination URL for this HTTP request. The values and formatting for the URL are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1.

    parameters

    The parameters for this HTTP request. The values and formatting are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1.

    Return Value

    The newly initialized request object.

    Discussion

    Use this method to initialize an SLRequest. The value and formatting of each parameter is dependent on the target service.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • account account Property

    Account information used to authenticate the request.

    Declaration

    Swift

    var account: ACAccount!

    Objective-C

    @property(retain, nonatomic) ACAccount *account

    Discussion

    The account is used to sign a request with OAuth1 services or to add an access token for OAuth2 services. By associating the account with the request, the necessary tokens are added automatically. The default value is nil.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • The method to use for this request. (read-only)

    Declaration

    Swift

    var requestMethod: SLRequestMethod { get }

    Objective-C

    @property(readonly, nonatomic) SLRequestMethod requestMethod

    Discussion

    Use this property to look up the method of the HTTP request that was set in requestForServiceType:requestMethod:URL:parameters:. Possible values are described in SLRequestMethod.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • URL URL Property

    The destination URL for this request. (read-only)

    Declaration

    Swift

    var URL: NSURL! { get }

    Objective-C

    @property(readonly, nonatomic) NSURL *URL

    Discussion

    Use this property to look up the URL of the HTTP request that was set in requestForServiceType:requestMethod:URL:parameters:. Possible values are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • The parameters for this request. (read-only)

    Declaration

    Swift

    var parameters: [NSObject : AnyObject]! { get }

    Objective-C

    @property(readonly, nonatomic) NSDictionary *parameters

    Discussion

    Use this property to look up the query parameters of the HTTP request that was set in requestForServiceType:requestMethod:URL:parameters:. Possible values are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • Performs an asynchronous request and calls the specified handler when done.

    Declaration

    Swift

    func performRequestWithHandler(_ handler: SLRequestHandler!)

    Objective-C

    - (void)performRequestWithHandler:(SLRequestHandler)handler

    Parameters

    handler

    The handler to call when the request is done. The parameters for this handler are described in SLRequestHandler. This handler is not guaranteed to be called on any particular thread and should not be nil.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • Returns an authorized URL request that can be sent using an NSURLConnection object.

    Declaration

    Swift

    func preparedURLRequest() -> NSURLRequest!

    Objective-C

    - (NSURLRequest *)preparedURLRequest

    Return Value

    An OAuth-compatible NSURLRequest object that allows an app to act on behalf of the user while keeping the user’s password private. The NSURLRequest is signed as OAuth1 by default, or OAuth2 by adding the appropriate token based on the user’s account.

    Discussion

    Use this method to modify your request before sending. By setting the account correctly, this method will automatically add any necessary tokens.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • Specifies a named multipart POST body for this request.

    Declaration

    Objective-C

    - (void)addMultipartData:(NSData *)data withName:(NSString *)name type:(NSString *)type

    Parameters

    data

    The data for the multipart POST body, such as an image or text.

    name

    The name of the multipart POST body. This is the name that a specific social service expects.

    type

    The type of the multipart POST body. This is the MIME content type of the multipart data.

    Discussion

    Possible parameter values are dependent on the target service. This information, as well as guidance on when to use a multipart POST body, is documented by the service provider. For links to documentation for the supported services, see Table 1.

    Import Statement

    Availability

    Available in OS X v10.8 and later.

    Deprecated in OS X v10.8.

  • Specifies a named multipart POST body for this request.

    Declaration

    Swift

    func addMultipartData(_ data: NSData!, withName name: String!, type type: String!, filename filename: String!)

    Objective-C

    - (void)addMultipartData:(NSData *)data withName:(NSString *)name type:(NSString *)type filename:(NSString *)filename

    Parameters

    data

    The data for the multipart POST body, such as an image or text.

    name

    The name of the multipart POST body. This is the name that a specific social service expects.

    type

    The type of the multipart POST body. This is the MIME content type of the multipart data.

    filename

    The filename of the attachment that you want to POST. Many social services require a filename in order to accept certain POST requests, such as uploading an image or video. If your multipart data does not require a filename, pass in nil.

    Discussion

    Possible parameter values are dependent on the target service. This information, as well as guidance on when to use a multipart POST body, is documented by the service provider. For links to documentation for the supported services, see Table 1.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

Data Types

  • The callback handler for a request.

    Declaration

    Swift

    typealias SLRequestHandler = (NSData!, NSHTTPURLResponse!, NSError!) -> Void

    Objective-C

    typedef void(^SLRequestHandler)(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error);

    Discussion

    The parameters for this handler are:

    responseData

    The data returned by the request. The format of this data is dependent on the target service.

    urlResponse

    The URL response returned by the request that includes the HTTP response codes.

    error

    An error identifier.

    Possible values are dependent on the target service and are documented by the service provider. For links to documentation for the supported services, see Table 1.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.

  • Possible values for the serviceType parameter.

    Declaration

    Swift

    let SLServiceTypeFacebook: NSString! let SLServiceTypeTwitter: NSString! let SLServiceTypeSinaWeibo: NSString! let SLServiceTypeLinkedIn: NSString! let SLServiceTypeTencentWeibo: NSString!

    Objective-C

    NSString *const SLServiceTypeFacebook; NSString *const SLServiceTypeTwitter; NSString *const SLServiceTypeSinaWeibo; NSString *const SLServiceTypeLinkedIn; NSString *const SLServiceTypeTencentWeibo;

    Constants

    • SLServiceTypeFacebook

      SLServiceTypeFacebook

      A string constant that identifies the social networking site, Facebook.

      Available in OS X v10.8 and later.

    • SLServiceTypeTwitter

      SLServiceTypeTwitter

      A string constant that identifies the social networking site, Twitter.

      Available in OS X v10.8 and later.

    • SLServiceTypeSinaWeibo

      SLServiceTypeSinaWeibo

      A string constant that identifies the social networking site, Sina Weibo.

      Available in OS X v10.8 and later.

    • SLServiceTypeLinkedIn

      SLServiceTypeLinkedIn

      A string constant that identifies the social networking site, LinkedIn.

      Available in OS X v10.9 and later.

    • SLServiceTypeTencentWeibo

      SLServiceTypeTencentWeibo

      A string constant that identifies the social networking site, Tencent Weibo.

      Available in OS X v10.9 and later.

    Import Statement

  • Indicates the request method used in the request.

    Declaration

    Swift

    enum SLRequestMethod : Int { case GET case POST case DELETE case PUT }

    Objective-C

    typedef NS_ENUM (NSInteger, SLRequestMethod ) { SLRequestMethodGET, SLRequestMethodPOST, SLRequestMethodDELETE, SLRequestMethodPUT; };

    Constants

    • GET

      SLRequestMethodGET

      Requests information from the specified resource. Use a GET request to fetch information from the specified server such as character limits or a user’s timeline.

      Available in OS X v10.8 and later.

    • POST

      SLRequestMethodPOST

      Submits data to be processed. Use a POST request to submit information to the specified server such as a status update or an image.

      Available in OS X v10.8 and later.

    • DELETE

      SLRequestMethodDELETE

      Deletes the specified resource.

      Available in OS X v10.8 and later.

    • PUT

      SLRequestMethodPUT

      Uses a PUT request to submit the data.

      Available in OS X v10.9 and later.

    Discussion

    Use this constant to set the requestMethod property. The type of request to use depends on the target service. For links to documentation for the supported services, see Table 1.

    Import Statement

    import Social

    Availability

    Available in OS X v10.8 and later.