我正在使用Twitter API,我想获得access_Token但是我收到了这个错误:
{
"errors" : [
{
"message" : "Missing required parameter: grant_type",
"label" : "forbidden_missing_parameter",
"code" : 170
}
]
}.
我的要求如下:
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)
}
}
}
我试图获取access_Token(OAuth)但无法获取因为上述错误即将发生。
答案 0 :(得分:0)
我也遇到过类似的问题,并且使用本机NSMutableURLRequest进行了修复。 https://stackoverflow.com/a/59472862/1528061