I'm at my wit's end on this. I've done tons of research, read all the Google docs on OAuth2 authentication and I'm being stopped developing my iOS app by this one, stupid problem.
I'm trying to get an access token from a refresh token that I obtained from the OAuth2 playground. I know the token is valid because I can use the refresh token to gain an access token in the playground, but when I make an http request through code I'm always getting a 401 unauthorized response.
The documentation says that when your context is an iOS app that you don't need to use the secret_key parameter in your URL:
" (The client_secret is not applicable to requests from clients registered as Android, iOS, or Chrome applications.)"
This is my request URL:
let url1 = URL(string: "https://www.googleapis.com/oauth2/v4/token?grant_type=refresh_token&refresh_token={REFRESH TOKEN TEXT HERE}&client_id={CLIENT ID}")
I have a feeling the problem is the clientID. I've used Google's credentials wizard to add credentials to my project and it says:
"You already have credentials that are suitable for this purpose"
and it gives the client ID. However the client ID that it gives returns this 401 unauthorized error.
Can anyone help???