使用以下代码和我尝试过的许多其他变体,我总是收到未经授权的错误。我正在使用使用CocoaPods 的TwitterKit 3.0。我已经设置了 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")
}
}
}
}
“发送推文时遇到错误:错误域=TWTRNetworkingErrorDomain Code=-1011 “请求失败:未经授权(401)” UserInfo={NSLocalizedFailureReason=, TWTRNetworkingStatusCode=401, NSErrorFailingURLKey= https://api.twitter.com/1.1/statuses/ update.json , NSLocalizedDescription=请求失败:未授权 (401)"