{error =“invalid_request”; “error_description”=“缺少必需参数:grant_type”;在快速

时间:2017-06-28 11:25:38

标签: ios swift alamofire

I am trying with this but every time I will get 

{     error = "invalid_request";     "error_description" = "Required parameter is missing: grant_type"; }

Request String: 

let headers    = [ "Content-Type" : "application/x-www-form-urlencoded"]

let urlString = "https://accounts.google.com/o/oauth2/token?"

Alamofire.request(urlString, method: .post, parameters: ["grant_type":"authorization_code","code":"4/FAOYR1mQo1lN1Gdg9jDnigwZ8RP76NUrqPbYZlMCSP28","client_id":"387376833747-12pbtud9tepr4di0insdhc0d4qpf5e9m.apps.googleusercontent.com","client_secret":"xOacVhLavM9fH8SpOK4I2dRJ","redirect_uri":"https://stackoverflow.com"], encoding: JSONEncoding.default, headers : headers)
            .responseJSON { response in
                print(response)
                print(response.result)
        }

也尝试传递这样的请求参数,但仍然不适用于我。

2 个答案:

答案 0 :(得分:0)

发布请求时,您无法使用网址发送附加参数。 传递参数如下

  let headers    = [ "Content-Type" : "application/x-www-form-urlencoded","grant_type" : "authorization_code"" ]

        let urlString = "https://accounts.google.com/o/oauth2/token?"
            Alamofire.request(urlString, method: .post, parameters: ["code":"4/FAOYR1mQo1lN1Gdg9jDnigwZ8RP76NUrqPbYZlMCSP28","client_id":"apps.googleusercontent.com","client_secret":"","redirect_uri":"https://stackoverflow.com"], encoding: JSONEncoding.default, headers : headers)
                .responseJSON { response in
                    print(response)
                    print(response.result)
            }

答案 1 :(得分:-1)

这些错误invalid_request仅在案例下发生,因此请向服务器端查询缺失或无效的内容。

  

请求缺少必需参数,包括不受支持的参数   或者参数值无效,重复参数,包括多个   凭证,利用多种机制进行身份验证   客户,或者其他方面都是畸形的。