Error 'Missing required parameter : grant_type' using Swift 3

本小妞迷上赌 提交于 2019-12-25 08:59:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!