2017-08-31 72 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