Demo SDK for fetching Tweets with the Twitter API
- iOS 9.0+
- Swift 3.1 or Objective-C
To use the SDK with CocoaPods add the following lines to your podfile's target:
use_frameworks!
pod 'TwitterSearchKit', :git => 'https://github.com/juxs/TwitterSearchKit.git'
Download the project and drag the TwitterSearchKit.xcodeproj
file into your XCode's project navigator.
Objective C classes are using the TS prefix. For instance, TwitterSearchKit becomes TSTwitterSearchKit.
Add @import TwitterSearchKit;
to the Objective C file.
First the Twitter API credentials have to be set in the AppDelegate. It must be a Base64 encoded string containing the format consumerKey:consumerSecret (as described here). ConsumerKey and ConsumerSecret can be obtained on https://dev.twitter.com and are used for application-only API requests
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
//Set Twitter credentials
TwitterSearchKit.tokenCredentials = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
return true
}
This is the implementation for fetching tweets with a given search term (the string of a hashtag):
TwitterSearchKit.getTweets(withSearchTerm: "AnyHashtagString") { (tweets) in
//parse tweets
}
Tweets are asynchronously fetched and returned as an optional array of Dictionaries. Each dictionary contains the raw Twitter API response. The request failed if the array is nil. If that's the case make sure your API credentials are set correctly.
There are sample apps in this repository.
To run check out this repo and open the Library project file as the samples are targets.