问题
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
}
]
}.
My request is below:
let dict = ["grant_type" : "client_credentials"]
requestPOSTURL("https://api.twitter.com/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)
}
}
}
Here I am trying to get access_Token (OAuth) but not able to get because above errors are coming.
回答1:
I have faced the similar issue, and it get fixed with native NSMutableURLRequest. https://stackoverflow.com/a/59472862/1528061
来源:https://stackoverflow.com/questions/45033645/error-missing-required-parameter-grant-type-using-swift-3