ios - 使用 Swifter Framework 快速检索 Twitter 用户图像和名称

标签 ios 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")
    })

最佳答案

遇到同样问题的 friend :

  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 用户名和个人资料图片。

关于ios - 使用 Swifter Framework 快速检索 Twitter 用户图像和名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29042785/

相关文章:

ios - 将小数格式化为在最后一个零之后有四个非零数字

ios - 无法加载 bundle “CheckoutTests”,因为它已损坏或缺少必要的资源。尝试重新安装 bundle

ios - Twitter OAuth 1 POST 请求不起作用

java - 编译但崩溃的 Android 应用程序。与 Intent 有关吗?帮助

ios - UIAttachment 在 iOS 7 中不起作用

ios - 如何从 swift 类到 Objective C 类访问变量

ios - 推送新的 View Controller 时,自定义导航栏 subview 不会隐藏

ios - UIViewRepresentable 自身相对于其中的 UIKit 控件的大小如何?

ios - 如何在 Swift 中更改 UIPickerView 中的字体大小?

python - 尝试获取 Twitter 授权的访问 key 时出现 401 错误