ios - 错误响应 TwitterKit

标签 ios swift twitter twitterkit

我有一个请愿 url 请求,但问题是响应数据为 nil ,对于其他 url 请求,请愿成功但没有这个功能!任何想法 ?

let client = TWTRAPIClient()
    let statusesShowEndpoint = "https://api.twitter.com/1.1/statuses/home_timeline.json"
    //let params = ["id": "20"]
    var clientError : NSError?

    let request = client.urlRequest(withMethod: "GET", url: statusesShowEndpoint, parameters: nil, error: &clientError)


    client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
        if connectionError != nil {
            print("Error: \(connectionError)")
        }

        do {
            let json = try JSONSerialization.jsonObject(with: data!, options: [])
            print("json: \(json)")
        } catch let jsonError as NSError {
            print("json error: \(jsonError.localizedDescription)")
        }
    }

控制台出现错误

"Request failed: forbidden (403)" UserInfo={NSLocalizedFailureReason=Twitter API error : Your credentials do not allow access to this resource. (code 220), TWTRNetworkingStatusCode=403, NSErrorFailingURLKey=https://api.twitter.com/1.1/statuses/home_timeline.json, 

但是对于这个请求是独占的,其他请求api不会出现这个错误。

最佳答案

尝试使用这段代码,它对我有用:

var userID: String = Twitter.sharedInstance().sessionStore.session.userID
var client = TWTRAPIClient(userID: userID)

关于ios - 错误响应 TwitterKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45979401/

相关文章:

ios - 无法在 performSelectorInBackground 中调用实例方法

ios - IOS 导航 Controller 的 InterativeSideMenu 库问题

SwiftUI:删除行时使用 Array/Index 的 ForEach 崩溃

php - 将多个社交媒体网站上的关注者数量提升到一种XML

ios - 在 Spritekit Xcode 中添加爆炸的最佳方法

ios - 未调用 UICollectionView 方法(collectionView cellForItemAt indexPath)

ios - 用 Dictionary 类型的参数声明的函数显示另一个参数类型

ios - 无法访问 XCTestCase 对象(或任何引用它的对象)中的 AppDelegate

Android Twitter Oauth 获取屏幕名称

ruby - 如何通过 Twitter API https ://api. twitter.com/1.1/direct_messages/events/new.json 发送新的直接消息?