7

I'm trying to get access to Google Drive API and I read documentation. My iOS app sends first request to ask for permission to endpoint https://accounts.google.com/o/oauth2/v2/auth.

User grants permission. I get a code. Next step is to authorization code for refresh and access tokens.

As for installed apps, I don't need to send client secret. In order to do that iOS app sends POST request to the endpoint:

https://www.googleapis.com/oauth2/v4/token

with headers:

Content-Type : application/x-www-form-urlencoded

body:

code={CODE_FROM_OAUTH_SERVER}&client_id={CLIENT_ID_FROM_CONSOLE}&redirect_uri={APP_BUNDLE_IDENTIFIER}:/code&grant_type=authorization_code

I get the response:

{
  "error": "unsupported_grant_type",
  "error_description": "Invalid grant_type: "
}

App is registered in Google console.

My question is am I doing something wrong?

Satheesh
  • 10,998
  • 6
  • 50
  • 93
Yurii Boiko
  • 321
  • 1
  • 8

2 Answers2

3

It is sending the specified data in a POST request to the HTTP server, same as when browser do when we fill a HTML form and do submit . This will cause to pass the data to the server using the content-type application/x-www-form-urlencoded.

You should try by changing the way you pass the OAuth parameters like client_id, ,redirect_uri, grant_type, etc.

Or should try making Native client of default type.

Alfran
  • 1,301
  • 1
  • 10
  • 19
0

One possible source of parsing errors is the redirect_uri . It should be url-encoded.

Alfran
  • 1,301
  • 1
  • 10
  • 19
Rondo
  • 3,458
  • 28
  • 26