测试已测试 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布了最后发布 | 2015年8月 |
SPM支持SPM | ✗ |
由Kyle Goslan维护。
依赖 | |
Alamofire | ~> 1.3 |
SwiftyJSON | ~> 2.2.1 |
TwitterJSON让iOS设备上的Twitter REST API易于使用。你只需几行代码即可开始收到响应。它使用设备上的账户来授权请求。
你只需一个方法调用就可以从Twitter得到结果。例如,获取用户的主帖
TwitterJSON.getHomeFeed { (tweets) -> Void in
}
所有方法都是TwitterJSON
类的类方法,所以无需初始化任何对象。上面的示例中,完成处理程序包含一个TJTweet对象的数组。每个对象都代表一个推文。你现在可以对这些推文的数组做任何你想要的事情,例如
TwitterJSON.getHomeFeed { (tweets) -> Void in
for tweet in tweets {
println(tweet.user.name)
println(tweet.text)
}
}
就这样!
默认情况下,所有返回包含推文或用户数组的请求都将返回20个结果。这是定义为静态类变量,这意味着当你设置它时,它将保持在该值,直到稍后更改。要更改结果数量
TwitterJSON.numberOfResults = 5
注意:Twitter的REST API请求有数量限制。
以下方法获取推文,并将返回TJTweet对象的数组。
TwitterJSON.getHomeFeed { (tweets) -> Void in
//Returns tweets from the users home feed.
}
TwitterJSON.searchForTweets("Apple", completion: { (tweets) -> Void in
//Returns tweets containing the given search query.
})
注意:所有推文还包括一个TJUser
对象,该对象包含发布推文用户的个人信息。
以下方法获取用户,并返回TJUser对象的数组。
TwitterJSON.getFollowersForUser("KyleGoslan", completion: { (users) -> Void in
//Returns a list of followers following the specified user.
})
TwitterJSON.getFollowingForUser("KyleGoslan", completion: { (users) -> Void in
//Returns a list of people the specified user is following.
})
以下方法将数据发送到Twitter,并返回一个布尔值以表示成功。
TwitterJSON.postTweet("Hello World", completion: { (success) -> Void in
//Will post the given string to twitter.
})
TwitterJSON.retweet(123456789, completion: { (success) -> Void in
//Will retweet the tweet with the given ID.
})
TwitterJSON.favoriteTweet(123456789, completion: { (success) -> Void in
//Will favorite the tweet with the given ID.
})