2015-07-19 46 views
1

我正在检索并显示表格视图中的推文列表。以下代码从搜索中抓取一大堆推文并显示它们。这工作正常!TwitterKit - TWTRSearchTimelineDataSource搜索查询格式

Twitter.sharedInstance().logInGuestWithCompletion { session, error in 
     if let _ = session { 
      let client = Twitter.sharedInstance().APIClient 
      self.dataSource = TWTRSearchTimelineDataSource(searchQuery: "cats", APIClient: client) 
     } else { 
      print("error: \(error.localizedDescription)") 
     } 
    } 

但是,当我更改搜索查询以获取推特引用特定用户时,我只是得到一个空白屏幕。

Twitter.sharedInstance().logInGuestWithCompletion { session, error in 
     if let _ = session { 
      let client = Twitter.sharedInstance().APIClient 
      self.dataSource = TWTRSearchTimelineDataSource(searchQuery: "@mtasummit", APIClient: client) 
     } else { 
      print("error: \(error.localizedDescription)") 
     } 
    } 

我试图用几种方法对'@'符号进行编码,而且这种方式似乎也不起作用。我究竟做错了什么?

回答

1

我忽略了API中的一个小细节:

“还要注意的是,在twitter.com搜索结果可能返回历史结果,而搜索API,通常只能从过去的一周成为鸣叫” (https://dev.twitter.com/rest/public/search

我之所以没有看到任何推文,是因为我的搜索字词“@mtasummit”仅包含几个月前的结果,所以他们没有被检索。

+1

感谢您的回复。在2k17中,我发现这个“请记住,搜索索引有7天的限制,换句话说,在超过一周的日期内不会发现任何推文。”这里:https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets –