本文介绍了错误“缺少必需的参数:grant_type"使用 Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理 Twitter API,我想获取 access_Token 但我收到此错误:
I am working on Twitter API and I want to get access_Token but I am getting this error:
{ "errors" : [ { "message" : "Missing required parameter: grant_type", "label" : "forbidden_missing_parameter", "code" : 170 } ] }.我的要求如下:
let dict = ["grant_type" : "client_credentials"] requestPOSTURL("api.twitter/oauth2/token", params: dict as [String : AnyObject] , headers: ["Authorization" : "Basic " + strHeader, "Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8"], success: { (json) in Helper.sharedInstance.Print(json as AnyObject) }, failure: {(error) in Helper.sharedInstance.Print(error as AnyObject) }). func requestPOSTURL(_ strURL : String, params : [String : AnyObject]?, headers : [String : String]?, success:@escaping (JSON) -> Void, failure:@escaping (Error) -> Void){ sessionManager.request(strURL, method: .post, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { (responseObject) -> Void in //print(responseObject) if responseObject.result.isSuccess { let resJson = JSON(responseObject.result.value!) success(resJson) } if responseObject.result.isFailure { let error : Error = responseObject.result.error! failure(error) } } }这里我正在尝试获取 access_Token (OAuth),但由于出现上述错误而无法获取.
Here I am trying to get access_Token (OAuth) but not able to get because above errors are coming.
推荐答案我也遇到过类似的问题,并且通过原生 NSMutableURLRequest 解决了这个问题.stackoverflow/a/59472862/1528061
I have faced the similar issue, and it get fixed with native NSMutableURLRequest. stackoverflow/a/59472862/1528061
更多推荐
错误“缺少必需的参数:grant
发布评论