2017-08-31 55 views
0

我有一个请愿url请求,但问题是响应数据为零,与其他url请求petiton成功,但与此功能!任何想法 ?错误响应TwitterKit

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不会出现此错误。

回答

1

尝试使用此代码,它的工作对我来说:

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

WOOW,谢谢! – Alejandro