iOS TWTRComposer请求失败:未经授权(401) [英] iOS TWTRComposer Request failed: unauthorized (401)

查看:1321
本文介绍了iOS TWTRComposer请求失败:未经授权(401)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码和我尝试过的其他一些变体,我总是会收到未经授权的错误。我正在使用CocoaPods TwitterKit 3.0 。我有我的plist设置,我的twitter应用程序配置,以及这样的代码:

With the following code and a bunch of other variations I've tried, I always get an unauthorized error. I'm using TwitterKit 3.0 using CocoaPods. I've got my plist setup, my twitter app configured, and code like this:

// 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代码= -1011请求失败:
unauthorized(401)UserInfo = {NSLocalizedFailureReason =,
TWTRNetworkingStatusCode = 401,
NSErrorFailingURLKey = https://api.twitter.com/1.1/statuses/update.json
NSLocalizedDescription =请求失败:未授权(401)

"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的设置说明操作后仍然无效,请尝试重新生成使用者密钥。这解决了我的问题。

If it doesn't work even after following Twitter's setup instructions, try regenerating the consumer keys. This fixed the problem for me.

这篇关于iOS TWTRComposer请求失败:未经授权(401)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆