首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用更快捷的框架快速检索Twitter用户的图片和名称

使用更快捷的框架快速检索Twitter用户的图片和名称
EN

Stack Overflow用户
提问于 2015-03-13 22:07:11
回答 1查看 1K关注 0票数 1

我使用更快的框架来使用特定的哈希标签获取tweet,但我也需要用户的图像和名称。

使用这种方法,我可以获得tweet文本,我可以从JSON响应、概要文件图像和用户名中读取,但是我无法将它放入变量中。

PS:不介意for索引0.19它只是测试

代码语言:javascript
复制
        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")
    })
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-01 15:37:22

任何发现同样问题的人:

代码语言:javascript
复制
  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用户名和概要文件图像。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29042785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档