swift - Connecting the twitter api with native IOS -
i'm trying embed tweets tableview, seem can done using fabric. keep getting bad request: 400 after i've followed exact step-by-step guide. far i've added exact. why still error?
here i've done:
- added libraries , frameworks
twitterkitresources.bundle,twitterkit.framework,twittercore.framework - added
./fabric.framework/runrun script added appdelegate
twitter.sharedinstance().startwithconsumerkey("consumer key", consumersecret: "consumer secret") fabric.with([twitter.sharedinstance()])
added below tableviewcontroller.
import uikit import twitterkit class tweetsviewcontroller: uitableviewcontroller, twtrtweetviewdelegate { let tweettablereuseidentifier = "tweetcell" // hold loaded tweets var tweets: [twtrtweet] = [] { didset { tableview.reloaddata() } } let tweetids = ["603232039354114048"] override func viewdidload() { // setup table view self.title = "tweets" self.view.backgroundcolor = uicolor(rgba: "#f9f9f9") self.navigationcontroller?.navigationbar.bartintcolor = uicolor(rgba: "#b52519") self.view.backgroundcolor = uicolor(rgba: "#f9f9f9") tableview.estimatedrowheight = 150 tableview.rowheight = uitableviewautomaticdimension // explicitly set on ios 8 if using automatic row height calculation tableview.allowsselection = false tableview.registerclass(twtrtweettableviewcell.self, forcellreuseidentifier: tweettablereuseidentifier) // load tweets twitter.sharedinstance().apiclient.loadtweetswithids(tweetids) { tweets, error in if let ts = tweets as? [twtrtweet] { self.tweets = ts } else { println("failed load tweets: \(error.localizeddescription)") } } } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } // mark: - table view data source override func numberofsectionsintableview(tableview: uitableview) -> int { // #warning potentially incomplete method implementation. // return number of sections. return 1 } override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return self.tweets.count } override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let tweet = tweets[indexpath.row] let cell = tableview.dequeuereusablecellwithidentifier(tweettablereuseidentifier, forindexpath: indexpath) as! twtrtweettableviewcell cell.configurewithtweet(tweet) cell.tweetview.delegate = self return cell } override func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat { let tweet = tweets[indexpath.row] return twtrtweettableviewcell.heightfortweet(tweet, width: cgrectgetwidth(self.view.bounds)) } }
Comments
Post a Comment