我正在使用SWIFT查找所有提到“苹果”这个词的推文。
我使用的是twitter的开源库(https://github.com/mattdonnelly/Swifter/tree/xcode-6.3)。但是当调用api时,它只给出前32条tweet,而我想要所有的tweet。下面是我使用的代码
let swifter = Swifter(consumerKey: "", consumerSecret: "", appOnly: true)
swifter.authorizeAppOnlyWithSuccess({ (accessToken, response) -> Void in
// println("\(accessToken)")
swifter.getSearchTweetsWithQuery("apple", geocode: "", lang: "", locale: "", resultType: "", count: 150, until: "", sinceID: "2009-01-01", maxID: "", includeEntities: true, callback: "", success: { (statuses, searchMetadata) -> Void in
println(statuses
)
}) { (error) -> Void in
println(error)
}
// println("\(response)")
}, failure: { (error) -> Void in
// println(error)
})
}任何关于如何解决这个问题的建议,此外,如果有任何其他方法,那么它也欢迎。
发布于 2016-04-16 07:52:46
如果没有数十亿条推文,也有数百万条包含“苹果”这个字符串的推文。Twitter不会一次给你所有这些推文,因为它会让你的应用崩溃。你将需要fetch tweet来处理那些,(100似乎是最大值),如果你想要更多,你可以构造另一个fetch,例如:
swifter.getSearchTweetsWithQuery("apple", geocode: nil, lang: nil, locale: nil, resultType: nil, count: 100, until: "", sinceID: nil, maxID: "", includeEntities: true, callback: "", success: { (statuses, searchMetadata) -> Void in
print(statuses)
//if you need more continue with another fetch but set the maxID to the ID of the last tweet from the previous fetch
swifter.getSearchTweetsWithQuery("apple", geocode: nil, lang: nil, locale: nil, resultType: nil, count: 150, until: nil, sinceID: nil, maxID: idOfLastTweetFromPreviousFetch, includeEntities: true, callback: nil, success: { (statuses, searchMetadata) -> Void in
print(statuses)
}) { (error) -> Void in
print(error)
}
}) { (error) -> Void in
print(error)
}Swifter似乎是一个很好的库,但它几乎没有文档。相反,您需要使用twitter的文档来了解要传递的适当参数是什么。例如,此端点的文档可以在here中找到
https://stackoverflow.com/questions/36657886
复制相似问题