将twitter api与本机IOS连接

时间:2015-05-30 20:40:03

标签: ios swift twitter twitter-fabric

我正在尝试将推文嵌入到tableView中,这似乎可以通过使用fabric来完成。但是,在我按照确切的分步指南后,我会继续bad request: 400。到目前为止,我添加了确切的。为什么我仍然会收到此错误?

这就是我所做的:

  1. 添加了库TwitterKitResources.bundleTwitterKit.FrameworkTwitterCore.FrameWork
  2. 添加了./Fabric.framework/run运行脚本
  3. 将此添加到appDelegate

    Twitter.sharedInstance().startWithConsumerKey("Consumer key", consumerSecret: "Consumer secret") Fabric.with([Twitter.sharedInstance()])

  4. 将以下内容添加到我的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))
        }
    }
    

0 个答案:

没有答案