2017-06-28 532 views
-5
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) 
     } 

也嘗試傳遞這樣的請求參數,但仍然不適合我。{error =「invalid_request」; 「error_description」=「缺少必需的參數:grant_type」; }在迅速

回答

0

發佈請求時,您無法通過url發送附加參數。 傳遞參數,因爲這

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

authorization_code呢?我必須通過? –

+0

您需要按照我所述的方式通過。 – KKRocks

+0

我已經完成了與你所描述的相同,但我必須通過authorization_code值其他明智它給我錯誤未解決標識符authorization_code。 –

-1

這些錯誤INVALID_REQUEST下面只發生以下情況,請與您的服務器端缺什麼或作廢的支票。

缺少必需的參數的請求,包括一個不支持 或無效的參數值,重複的參數,包括多個 憑證,利用多於一個的機構,用於認證所述客戶機 ,或者以其他方式格式錯誤。

+0

所有需要的參數我已經放置了,我也嘗試了很多次相同的東西,但仍然無法得到正確的結果,請你幫我解決,因爲這個我不得不做其他的事情。 –

+0

@IOSdeveloper不能說你確切的是你在服務器端代碼中工作? –

+0

是的我已經在谷歌操場上實現了服務器端。 –

相關問題