401 unauthorized trying to use refresh token to get access token

657 views
Skip to first unread message

diamondde...@gmail.com

unread,
Sep 11, 2018, 5:39:31 PM9/11/18
to Google Calendar API
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???

diamondde...@gmail.com

unread,
Sep 11, 2018, 5:42:13 PM9/11/18
to Google Calendar API
One more thing that might be the problem - do I need to add the PLIST file to my Xcode project in order to get this to work? I noticed in the API Console that Google allows you to download PLIST files for the userIDs, but the OAuth2 documentation doesn't say anything about adding a PLIST file being necessary for access.
Reply all
Reply to author
Forward
0 new messages