Manually Create Twitter Requests

ios
swift

#1

The Fabric Docs show a way to manually create twitter requests here: https://docs.fabric.io/ios/twitter/access-rest-api.html#constructing-a-twitter-request-manually
but when I attempt to use this method in my app using Swift, I have multiple errors appear.

I know these all have to do with updated versions of Error Handling, but does anyone have the updated syntax in Swift to manually create these Twitter Get Requests using Fabric.

Thanks


#2

Hey @DaveMacG

Thanks for reporting this and here’s an updated sample. The public docs will also be updated with the correct code shortly.

// Swift
let client = TWTRAPIClient()
let statusesShowEndpoint = "https://api.twitter.com/1.1/statuses/show.json"
let params = ["id": "20"]
var clientError : NSError?

let request = client.URLRequestWithMethod("GET", URL: statusesShowEndpoint, parameters: params, error: &clientError)

client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
    if connectionError != nil {
        print("Error: \(connectionError)")
    }

    do {
        let json = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
        print("json: \(json)")
    } catch let jsonError as NSError {
        print("json error: \(jsonError.localizedDescription)")
    }
}

#3

Thanks for looking into this so quickly.

When I plug that new code in, I still receive an error:

If I delete that “extra argument”, a new/the same error from my first post appears “Call can throw, but it is not marked with ‘try’ and the error is not handled”.

Please assist. Thanks in advance.


#4

Hmm, that’s a bit odd then. Which version of Twitter Kit are you using?


#5

I actually was just manipulating and editing the Twitter Kit Sample provided in the documentation. I downloaded the zip from: https://github.com/twitterdev/FabricWithTwitter


#6

Ahh, that is a bit out of date, sorry about that. To get the latest, head here for instructions to get the code via Cocoapods or through Fabric.app.


#7

that worked, thanks @bonnell


#8