本文介绍了使用 TwitterKit/Fabric 身份验证失败获取单个推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 TwitterKit 中提供的 TWTRTweetView 检索单个推文并在我的应用程序中显示它.我遵循了本面料指南并最终得到以下代码.

I'm trying to retrieve a single tweet and show it in my application via the TWTRTweetView provided in the TwitterKit. I've followed this Fabric guide and ended up with following code.

import UIKit
import TwitterKit


class SingleTweetViewController: UIViewController{


@IBOutlet weak var plainView: UIView!

override func viewDidLoad(){
    super.viewDidLoad()

    Twitter.sharedInstance().logInGuestWithCompletion { session, error in
        if let validSession = session {
            Twitter.sharedInstance().APIClient.loadTweetWithID("4831830029115392") { tweet, error in
                if let t = tweet {
                    let tweetView = TWTRTweetView(tweet: tweet)
                    tweetView.showActionButtons = true
                    self.plainView.addSubview(tweetView)
                } else {
                    println("Failed to load Tweet: \(error?.localizedDescription)")
                }
            }

        } else {
            println("Unable to login as guest: \(error.localizedDescription)")
            println(error?.localizedFailureReason)
        }
    }
}

由于身份验证失败,代码生成了这两个错误.

The code generates these two errors due to authentication failure.

Unable to login as guest: Request failed: forbidden (403)
Optional("Twitter API error : Unable to verify your credentials (code 99)")

值得一提的是,该应用通过在 本指南.有没有人知道如何修复这个错误?我在这里遗漏了一些代码还是与 Fabric 相关的问题?

It is worth mentioning that the app successfully signs in to Twitter via the login button added following this guide. Does anyone have a clue how this error could be fixed? Am I missing some code here or is the issue related to Fabric?

推荐答案

我使用 Fabric 应用程序内置选项在应用程序中查看推文"解决了这个问题,该选项与添加登录按钮按钮"选项位于同一菜单中.Fabric 应用程序然后将正确的身份验证密钥插入到 Info.plist 文件中.Fabric 应用程序提供的代码似乎与 Fabric docs 但结果因您使用的而异.两个代码示例如下所示:

I solved the problem using Fabric applications built in option "View tweet in application" found in the same menu as the "Add login button button" option. The Fabric application then inserts proper authentication keys into the Info.plist file. The code provided by Fabric application seems to do the same thing as the code given on Fabric docs but the result differs depending on which one you use. The two code samples look like this:

来自 Fabric 文档的代码:

Code from Fabric docs:

Twitter.sharedInstance().logInGuestWithCompletion { session, error in
  if let validSession = session {
    Twitter.sharedInstance().APIClient.loadTweetWithID("20") { tweet, error in
      if let t = tweet {
        self.tweetView.configureWithTweet(t)
      } else {
        println("Failed to load Tweet: \(error.localizedDescription)")
      }
    }
  } else {
     println("Unable to login as guest: \(error.localizedDescription)")
  }
}

来自 Fabric 应用程序的代码:

Code from Fabric application:

Twitter.sharedInstance().logInGuestWithCompletion { (session, error) in
        Twitter.sharedInstance().APIClient.loadTweetWithID("20") { (tweet, error) in
            self.view.addSubview(TWTRTweetView(tweet: tweet))
        }
    }

运行第一个代码将出现身份验证错误,而第二个将加载一条推文而不会出现问题.if 语句 if let validSession = session 返回 false 并发生身份验证错误.我找不到 validSession 究竟是什么,但它可能比较两组不同的键或类似的东西.

Running the first code will give an authentication error while the second one will load a tweet without issues. The if-statement if let validSession = session returns a false and an authentication error occurs. I couldn't find what the validSession is exactly but it probably compares two different sets of keys or something similar.

这篇关于使用 TwitterKit/Fabric 身份验证失败获取单个推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 19:59