Marcos Griselli Marcos Griselli - 2 years ago 112
Swift Question

Retrieve Twitter user images and names in swift using Swifter Framework

I'm using Swifter Framework to get tweets using a specific hashtag, but I also need the user image and name.

With this method I'm able to get the tweet text and I can read from the JSON response the profile image and username but I'm not able to get it into a variable.

PS: Don't mind about the for index 0...19 its just testing

let swifter = Swifter(consumerKey: "MyConsumerKey", consumerSecret: "MyConsumerSecret", appOnly: true)

swifter.authorizeAppOnlyWithSuccess({ (accessToken, response) -> Void in
swifter.getSearchTweetsWithQuery("%23realmadrid", geocode: nil, lang: nil, locale: nil, resultType: nil, count: 20, until: nil, sinceID: nil, maxID: nil, includeEntities: true, callback: nil, success: { (statuses, searchMetadata) -> Void in

for index in 0...19 {
if let statusText = statuses?[index]["text"].string {
if let statusName = statuses?[index]["screen_name"].string {
println("@%@", statusName)
if let statusImage = statuses?[index]["profile_image_url"].string {
println("@%@", statusImage)



}, failure: { (error) -> Void in
}, failure: { (error) -> Void in

Answer Source

To anyone who finds the same problem:

  if let statusName = statuses?[index]["user"]["screen_name"].string {
                    tweetsDictionary.setObject(statusName, forKey: "name")

  if let statusImage = statuses?[index]["user"]["profile_image_url"].string {
                    var string = statusImage.stringByReplacingOccurrencesOfString("_normal", withString: "", options: NSStringCompareOptions.BackwardsSearch, range: nil)
                    tweetsDictionary.setObject(string, forKey: "image")

This retrieves twitter username and profile image in the quality the user uploaded it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download