{"action":"opened","issue":{"url":"https://api.github.com/repos/OAuthSwift/OAuthSwift/issues/156","labels_url":"https://api.github.com/repos/OAuthSwift/OAuthSwift/issues/156/labels{/name}","comments_url":"https://api.github.com/repos/OAuthSwift/OAuthSwift/issues/156/comments","events_url":"https://api.github.com/repos/OAuthSwift/OAuthSwift/issues/156/events","html_url":"https://github.com/OAuthSwift/OAuthSwift/issues/156","id":121932072,"number":156,"title":"Update twitter status,authorization problem","user":{"login":"fewspider","id":3256161,"avatar_url":"https://avatars.githubusercontent.com/u/3256161?v=3","gravatar_id":"","url":"https://api.github.com/users/fewspider","html_url":"https://github.com/fewspider","followers_url":"https://api.github.com/users/fewspider/followers","following_url":"https://api.github.com/users/fewspider/following{/other_user}","gists_url":"https://api.github.com/users/fewspider/gists{/gist_id}","starred_url":"https://api.github.com/users/fewspider/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fewspider/subscriptions","organizations_url":"https://api.github.com/users/fewspider/orgs","repos_url":"https://api.github.com/users/fewspider/repos","events_url":"https://api.github.com/users/fewspider/events{/privacy}","received_events_url":"https://api.github.com/users/fewspider/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-13T17:30:50Z","updated_at":"2015-12-13T17:30:50Z","closed_at":null,"body":"OAuthSwift version is `0.4.8`\r\nTwitter API is `https://api.twitter.com/1.1/statuses/update.json`, \r\nyou can visit `https://dev.twitter.com/rest/reference/post/statuses/update` for more detail.\r\n\r\nWhen my parameters has `in_reply_to_status_id`,it return like below\r\n```json\r\n{\r\n  \"errors\" : [\r\n    {\r\n      \"message\" : \"Could not authenticate you.\",\r\n      \"code\" : 32\r\n    }\r\n  ]\r\n}\r\n```\r\nBut only send `status ` is ok, it is pretty odd.\r\nMy project use `https://github.com/Alamofire/Alamofire` to request the Twitter REST API.\r\nI write a method to fetch header,do not forget replace the oauth_token,oauth_token_secret and Config,for some personal reason,i don't want to expose it:\r\n```swift\r\nprivate static func buildHeaders(requestMethod: OAuthSwiftHTTPRequest.Method, url: NSURL, parameters: [String: AnyObject]) -> [String : String] {\r\n        let oauth_token = \"\" //replace it,for some personal reason,i don't want to expose it\r\n        let oauth_token_secret = \"\" //replace it,for some personal reason,i don't want to expose it\r\n\r\n        let c = OAuthSwiftClient(consumerKey: Config.consumerKey, consumerSecret: Config.consumerSecret, accessToken: oauth_token, accessTokenSecret: oauth_token_secret)\r\n        let credential = c.credential\r\n\r\n        let authorization = credential.authorizationHeaderForMethod(requestMethod,\r\n            url: url,\r\n            parameters: parameters)\r\n\r\n        let headers = [\"Authorization\": authorization]\r\n        return headers\r\n    }\r\n```\r\nand set the header\r\n```swift\r\nprivate static func setHeaders(mutableURLRequest: NSMutableURLRequest, oauthMethod:OAuthSwiftHTTPRequest.Method, url: NSURL, parameters: [String: AnyObject]) -> NSMutableURLRequest {\r\n        let headers = Router.buildHeaders(oauthMethod, url:url, parameters: parameters)\r\n        for (field, value) in headers {\r\n            mutableURLRequest.setValue(value, forHTTPHeaderField: field)\r\n        }\r\n        return mutableURLRequest\r\n    }\r\n```\r\nThe class is:\r\n```swift\r\n//\r\n//  Router.swift\r\n//  Twicrow\r\n//\r\n//  Created by fewspider on 15/9/28.\r\n//  Copyright © 2015年 fff. All rights reserved.\r\n//\r\n\r\nimport Foundation\r\nimport Alamofire\r\nimport SwiftyJSON\r\nimport OAuthSwift\r\n\r\nstruct Config {\r\n    static let consumerKey = \"\" // replace it\r\n    static let consumerSecret = \"\" // replace it\r\n    static let callbackURL = \"oauth-swift://oauth-callback/twitter\"\r\n}\r\n\r\nenum Router: URLRequestConvertible {\r\n    static let baseURLString = \"https://api.twitter.com/1.1\"\r\n\r\n    case ReadHomeTimeline([String: AnyObject])\r\n    case ReadUserTimeline([String: AnyObject])\r\n\r\n    case UpdateStatus([String: AnyObject])\r\n    case Retweet(Int)\r\n\r\n    var method: Alamofire.Method {\r\n        switch self {\r\n        case .UpdateStatus, .Retweet:\r\n            return .POST\r\n        default:\r\n            return .GET\r\n        }\r\n    }\r\n\r\n    var oauthMethod: OAuthSwiftHTTPRequest.Method {\r\n        switch self {\r\n        case .UpdateStatus, .Retweet:\r\n            return .POST\r\n        default:\r\n            return .GET\r\n        }\r\n    }\r\n\r\n    var path: String {\r\n        switch self {\r\n        case ReadHomeTimeline(_):\r\n            return \"/statuses/home_timeline.json\"\r\n        case ReadUserTimeline(_):\r\n            return \"/statuses/user_timeline.json\"\r\n        case UpdateStatus(_):\r\n            return \"/statuses/update.json\"\r\n        case .Retweet(let id):\r\n            return \"/statuses/retweet/\\(id).json\"\r\n        }\r\n    }\r\n\r\n    // MARK: URLRequestConvertible\r\n\r\n    var URLRequest: NSMutableURLRequest {\r\n        let URL = NSURL(string: Router.baseURLString)!\r\n        let absUrl = URL.URLByAppendingPathComponent(path)\r\n        let mutableURLRequest = NSMutableURLRequest(URL: absUrl)\r\n        mutableURLRequest.HTTPMethod = method.rawValue\r\n\r\n\r\n        switch self {\r\n        case .UpdateStatus(let parameters):\r\n            return Router.baseReturn(mutableURLRequest, oauthMethod: oauthMethod, absUrl: absUrl, parameters: parameters)\r\n        case .ReadHomeTimeline(let parameters):\r\n            return Router.baseReturn(mutableURLRequest, oauthMethod: oauthMethod, absUrl: absUrl, parameters: parameters)\r\n        case .ReadUserTimeline(let parameters):\r\n            return Router.baseReturn(mutableURLRequest, oauthMethod: oauthMethod, absUrl: absUrl, parameters: parameters)\r\n        default:\r\n            let parameters = [String: AnyObject]()\r\n            Router.setHeaders(mutableURLRequest, oauthMethod: oauthMethod, url: absUrl, parameters: parameters)\r\n            return mutableURLRequest\r\n        }\r\n    }\r\n\r\n    private static func baseReturn (mutableURLRequest: NSMutableURLRequest, oauthMethod:OAuthSwiftHTTPRequest.Method, absUrl: NSURL, parameters: [String : AnyObject]) -> NSMutableURLRequest {\r\n        let mur = Router.setHeaders(mutableURLRequest, oauthMethod: oauthMethod, url: absUrl, parameters: parameters)\r\n        return Alamofire.ParameterEncoding.URLEncodedInURL.encode(mur, parameters: parameters).0\r\n    }\r\n\r\n    private static func setHeaders(mutableURLRequest: NSMutableURLRequest, oauthMethod:OAuthSwiftHTTPRequest.Method, url: NSURL, parameters: [String: AnyObject]) -> NSMutableURLRequest {\r\n        let headers = Router.buildHeaders(oauthMethod, url:url, parameters: parameters)\r\n        for (field, value) in headers {\r\n            mutableURLRequest.setValue(value, forHTTPHeaderField: field)\r\n        }\r\n\r\n//        print(\"headers----\\(headers)\")\r\n\r\n        return mutableURLRequest\r\n    }\r\n\r\n    private static func buildHeaders(requestMethod: OAuthSwiftHTTPRequest.Method, url: NSURL, parameters: [String: AnyObject]) -> [String : String] {\r\n        let oauth_token = \"\" //replace it,for some personal reason,i don't want to expose it\r\n        let oauth_token_secret = \"\" //replace it,for some personal reason,i don't want to expose it\r\n\r\n        let c = OAuthSwiftClient(consumerKey: Config.consumerKey, consumerSecret: Config.consumerSecret, accessToken: oauth_token, accessTokenSecret: oauth_token_secret)\r\n        let credential = c.credential\r\n\r\n        let authorization = credential.authorizationHeaderForMethod(requestMethod,\r\n            url: url,\r\n            parameters: parameters)\r\n\r\n        let headers = [\"Authorization\": authorization]\r\n        return headers\r\n    }\r\n}\r\n\r\n```\r\nthe class to request\r\n```swift\r\nimport Alamofire\r\nimport OAuthSwift\r\nimport SwiftyJSON\r\n\r\nclass RequestApi {\r\n\r\n    typealias SuccessBlock = (resJson: JSON) -> Void\r\n    typealias FailureBlock = (errorDescription: String) -> Void\r\n\r\n    static let Manager = Session.sharedInstance.ApiManager()\r\n\r\n    private static func handle(result: Result<AnyObject>, success: SuccessBlock, failure: FailureBlock) {\r\n        switch result {\r\n        case .Success:\r\n            let resJson = JSON(result.value!)\r\n            success(resJson: resJson)\r\n        case .Failure(_, let error):\r\n            let description = (error as NSError).localizedDescription\r\n            Tip().show(TipType.Failure, text: description)\r\n            failure(errorDescription: description)\r\n        }\r\n    }\r\n\r\n    static func retweet(id: Int, success: SuccessBlock, failure: FailureBlock) {\r\n        Manager.request(Router.Retweet(id)).responseJSON  { request, response, result in\r\n            handle(result, success: success, failure: failure)\r\n        }\r\n    }\r\n\r\n    static func update(parameters: [String : AnyObject], success: SuccessBlock, failure: FailureBlock) {\r\n        Manager.request(Router.UpdateStatus(parameters)).responseJSON  { request, response, result in\r\n            handle(result, success: success, failure: failure)\r\n        }\r\n    }\r\n\r\n    static func readHomeTimeline(parameters: [String : AnyObject], success: SuccessBlock, failure: FailureBlock) {\r\n        Manager.request(Router.ReadHomeTimeline(parameters)).responseJSON  { request, response, result in\r\n            handle(result, success: success, failure: failure)\r\n        }\r\n    }\r\n\r\n    static func readUserTimeline(parameters: [String : AnyObject], success: SuccessBlock, failure: FailureBlock) {\r\n        Manager.request(Router.ReadUserTimeline(parameters)).responseJSON  { request, response, result in\r\n            handle(result, success: success, failure: failure)\r\n        }\r\n    }\r\n\r\n    static func fetchInstagramOembed(parameters: [String : AnyObject], success: SuccessBlock, failure: FailureBlock) {\r\n        Manager.request(InstagramRouter.FetchOembed(parameters)).responseJSON  { request, response, result in\r\n            handle(result, success: success, failure: failure)\r\n        }\r\n    }\r\n\r\n}\r\n```\r\nother class\r\n```swift\r\n//\r\n//  Session.swift\r\n//  Twicrow\r\n//\r\n//  Created by fewspider on 15/12/7.\r\n//  Copyright © 2015年 fff. All rights reserved.\r\n//\r\n\r\nimport Alamofire\r\n\r\nclass Session {\r\n    static let sharedInstance = Session()\r\n\r\n    private var manager : Manager?\r\n\r\n    func ApiManager() -> Manager {\r\n        if let m = self.manager {\r\n            return m\r\n        }else{\r\n            let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()\r\n            configuration.timeoutIntervalForRequest = 5\r\n\r\n            let tempmanager = Alamofire.Manager(configuration: configuration)\r\n            self.manager = tempmanager\r\n            return self.manager!\r\n        }\r\n    }\r\n}\r\n```\r\nReproduce the issue\r\n```swift\r\nvar dct = [String : AnyObject]()\r\ndct[\"in_reply_to_status_id\"] = 676067907940384768\r\ndct[\"status\"] = \"Test RT @fewspider: 还是仔细研究下 http://oauth.net/core/1.0a/\"\r\nRequestApi.update(dct, success: { (resJson) -> Void in\r\n        print(\"resJson----\\(resJson)\")\r\n    }, failure: { (errorDescription) -> Void in\r\n})\r\n```"}}