I am using drive.files.insert method from https://github.com/google/google-api-nodejs-client and it worked properly but I don't know how can I refresh the token and also where can I get the refresh token. Meanwhile, I am taking the token from https://developers.google.com/oauthplayground/ and with that token I am able to upload the files but as the access token valid only for 1 hour so I won't be able to upload the files after 1 hour and I won't know how to do that after 1 hour as I am unable to write get and post method. I saw from some sites, they are using gapi.client for authentication and then they uploading to drive but even it won't work. I hope I am able to explain my question well. Suggestions are always welcomed and thanks for the help in advance
Asked
Active
Viewed 113 times
1 Answers
0
It's all correct. Google always give you a token with 1 hour lifetime, you will not get any longer, but it's not an issue. Read a doc (from the library you pasted here carefully). It says:
You can start using OAuth2 to authorize and authenticate your requests to Google APIs with the retrieved tokens. If you provide a refresh_token and the access_token has expired, the access_token will be automatically refreshed and the request is replayed.
So if the access_token will be automatically refreshed there is no problem. You can always manually refresh your access token using refresh_token (you always get a pair access_token + refresh_token) but I don't think you need it. It's how Oauth2 works.

speedingdeer
- 1,236
- 2
- 16
- 26
-
Sir, can you provide me the complete method with some dummy data example for refreshing the token, it would be very helpful for me. – VIKAS KOHLI Jun 10 '16 at 13:07
-
The library you are suing is full of samples. Analyzing your question I'm not sure if you fully understand how the oAuth2 protocol works. I don't recommend you to refresh the token yourself. If the user gives you one the permission to use the app you just authorize the request each time when you need it. I suggest you to read https://developers.google.com/identity/protocols/OAuth2WebServer and pay attention to 'Calling Google APIs' section. Good luck! – speedingdeer Jun 10 '16 at 13:14