错误“缺少必需的参数:grant

编程入门 行业动态 更新时间:2024-10-08 20:34:46
本文介绍了错误“缺少必需的参数: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

本文发布于:2023-11-26 23:37:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635675.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   参数   grant

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!