Reputation: 21
I'm trying to access the home_timeline
request as per this example.
However, I keep getting following error:
'URLRequestWithMethod' with an argument list of type '(String, URL: String, parameters: NSArray, error: inout NSError?)'
func getHomeTimeLine(){
var clientError:NSError?
let params = []
let request = Twitter.sharedInstance().APIClient.URLRequestWithMethod(
"GET",
URL: "https://api.twitter.com/1.1/statuses/home_timeline.json",
parameters: params,
error: &clientError)
if request != nil {
Twitter.sharedInstance().APIClient.sendTwitterRequest(request) {
(response, data, connectionError) -> Void in
if (connectionError == nil) {
var jsonError : NSError?
let json : AnyObject? =
NSJSONSerialization.JSONObjectWithData(data,
options: nil,
error: &jsonError)
}
else {
println("Error: \(connectionError)")
}
}
}
else {
println("Error: \(clientError)")
}
}
Upvotes: 2
Views: 768
Reputation: 329
Actually, the method signature where it says 'URL' has been changed to 'URLString' the correct / updated method call (in Objective C) looks like this:
NSDictionary *params = @{@"include_email": @"true", @"skip_status": @"true"};
NSError *clientError;
NSURLRequest *request = [client URLRequestWithMethod:@"GET" URLString:@"https://api.twitter.com/1.1/account/verify_credentials.json" parameters:params error:nil];
Hope this helps someone!
Upvotes: 0
Reputation: 713
Try this:
let request: NSURLRequest? = Twitter.sharedInstance().APIClient.URLRequestWithMethod("GET", URL: "https://api.twitter.com/1.1/statuses/user_timeline.json",
parameters: ["screen_name" : username,
"count" : "20"] ,
error: &clientError)
Upvotes: 0
Reputation: 131
Define params as a dictionary and use it.
let params: Dictionary = Dictionary()
func getHomeTimeLine() {
var clientError:NSError?
let params: Dictionary = Dictionary<String, String>()
let request: NSURLRequest! = Twitter.sharedInstance().APIClient.URLRequestWithMethod(
"GET",
URL: "https://api.twitter.com/1.1/statuses/home_timeline.json",
parameters: params,
error: &clientError)
if request != nil {
Twitter.sharedInstance().APIClient.sendTwitterRequest(request!) {
(response, data, connectionError) -> Void in
if (connectionError == nil) {
var jsonError : NSError?
let json : AnyObject? =
NSJSONSerialization.JSONObjectWithData(data!,
options: nil,
error: &jsonError)
// check for json data
if (json != nil) {
println("response = \(json)")
} else {
println("error loading json data = \(jsonError)")
}
}
else {
println("Error: \(connectionError)")
}
}
}
else {
println("Error: \(clientError)")
}
}
Upvotes: 6