iOS TWTRComposer 请求失败 : unauthorized (401)

标签 ios twitterkit

使用以下代码和我尝试过的许多其他变体,我总是会遇到未经授权的错误。我正在使用 TwitterKit 3.0 和 CocoaPods。我已经设置了 plist,配置了我的 Twitter 应用程序,并且编写了如下代码:

// In didFinishLaunchingWithOptions
Twitter.sharedInstance().start(withConsumerKey:"XX", consumerSecret:"YYY")

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
{
    return Twitter.sharedInstance().application(app, open: url, options: options)
}

// In response to a click
Twitter.sharedInstance().logIn { session, error in
    if session != nil { // Log in succeeded
        let composer = TWTRComposer()

        composer.setText(tweetText)

        composer.show(from: self.navigationController!) { result in
            if (result == .done) {
                print("Successfully composed Tweet")
            } else {
                print("Cancelled composing")
            }
        }
    }
}

"Did encounter error sending Tweet: Error Domain=TWTRNetworkingErrorDomain Code=-1011 "Request failed: unauthorized (401)" UserInfo={NSLocalizedFailureReason=, TWTRNetworkingStatusCode=401, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/update.json, NSLocalizedDescription=Request failed: unauthorized (401)"

最佳答案

如果在按照 Twitter 的设置说明进行操作后仍无法正常工作,请尝试重新生成消费者 key 。这解决了我的问题。

关于iOS TWTRComposer 请求失败 : unauthorized (401),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44491349/

相关文章:

java - 在 ANDROID 上集成 Twitter Api(使用来自 twitter 的原生 api)

android - 推特登录的变化

swift - 请求失败 : forbidden (403) after adding the provided url from Firebase in the callback settings of the Twitter app

iOS NSDateFormatter 即使是 UTC 也需要 NSLocale

iphone - viewDidLoad 中错误报告的方向

ios - 使用 AWS DynamoDBScanExpression 查找列表中具有键的所有对象

ios - 在 Swift 中使用动画将按钮从一个 UITableViewCell 移动到另一个

ios - TwitterKit 3.0 和 TWTRLoginMethod

ios - 无法在 TableView 中的标签上打印 Twitter 响应

ios - Xcode:应用程序构建但不会运行并且无法在方案中选择可执行文件