I’d like to make an application that could access MY own Google Drive anytime, create files there, share them and so on.
According to https://developers.google.com/drive/service-accounts “Use regular Google accounts as application-owned accounts” the only think I need is to get access_token and refresh_token once, store them in my application and using refresh_token I can refresh my access_token (somehow).
I can get access_token using request something like
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/drive.file&redirect_uri=http://localhost;response_type=token&client_id=
After approve this application request in user dialog I will be redirected to my localhost and I will get access_token that expires in 3600 seconds.
The questions are:
1. How to get a refresh_token?
2. How to refresh access_token using refresh_token?
I don’t want to use Google’s API client library because it’s terrible (.NET).
Ok I got it.
The answer can be found here: https://developers.google.com/accounts/docs/OAuth2WebServer#offline
First You have to make an Auth request
Then you will get a ‘code’ to your return_url
Then you need to exchange the code to access_token and refresh_token
As a result of this you will bet response like:
Now you can store these tokens in your application and use for unlimited time refreshing the access_token every 3600 secs
And each time you make this request you will get a new access_token