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

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

问题描述:

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)
        }

也可以尝试传递这样的请求参数,但对我仍然不起作用。

Also try with passing request parameter like this but still doesn't work for me.

您不能使用以下命令发送附加参数发送请求时的网址。
传递参数,如下所示

You can't send appended parameter with url while post request. Pass parameter as below this

  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)
            }