使用 Swifter Framework 在 swift 中检索 Twitter 用户图像和名称



我正在使用Swifter Framework来获取使用特定主题标签的推文,但我还需要用户图像和名称。

使用这种方法,我能够获取推文文本,并且可以从 JSON 响应中读取个人资料图像和用户名,但我无法将其放入变量中。

PS:不介意索引 0...19 它只是测试

        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")
    })

对于发现相同问题的任何人来说:

  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")
                }

这将以用户上传的质量检索 Twitter 用户名和个人资料图像。

最新更新