我正在尝试将推文嵌入到tableView中,这似乎可以通过使用fabric来完成。但是,在我按照确切的分步指南后,我会继续bad request: 400
。到目前为止,我添加了确切的。为什么我仍然会收到此错误?
这就是我所做的:
TwitterKitResources.bundle
,TwitterKit.Framework
和TwitterCore.FrameWork
./Fabric.framework/run
运行脚本将此添加到appDelegate
Twitter.sharedInstance().startWithConsumerKey("Consumer key", consumerSecret: "Consumer secret")
Fabric.with([Twitter.sharedInstance()])
将以下内容添加到我的TableViewController
。
import UIKit
import TwitterKit
class TweetsViewController: UITableViewController, TWTRTweetViewDelegate {
let tweetTableReuseIdentifier = "TweetCell"
// Hold all the loaded Tweets
var tweets: [TWTRTweet] = [] {
didSet {
tableView.reloadData()
}
}
let tweetIDs = ["603232039354114048"]
override func viewDidLoad() {
// Setup the 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 to load tweets: \(error.localizedDescription)")
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the 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))
}
}