1

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 {
                    self.tweetsArray.addObject(statusText)
                }
                if let statusName = statuses?[index]["screen_name"].string {
                    println("@%@", statusName)
                }
                if let statusImage = statuses?[index]["profile_image_url"].string {
                    println("@%@", statusImage)
                }

            }

            self.tableView.reloadData()


        }, failure: { (error) -> Void in
        })
    }, failure: { (error) -> Void in
        println("error")
    })
Suhaib
  • 2,031
  • 3
  • 24
  • 36
Marcos Griselli
  • 1,306
  • 13
  • 22

1 Answers1

3

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.

Marcos Griselli
  • 1,306
  • 13
  • 22
  • Can you describe the code a little bit? What is `statuses` for example? Would be great if you could explain the whole code. – Lukesivi Nov 28 '15 at 17:46
  • I tried your suggestion but I am still having problems. Please see https://stackoverflow.com/questions/49691187/post-a-tweet-with-a-photo-using-the-swifter-framework-library I need assistance. Thank you so much – Ben Akin Apr 06 '18 at 10:59