简体   繁体   中英

Google Drive Session Expiry

From my understanding, when using the Drive Java API it is recommended to build an instance of the Drive class and then store it so that it can then be shared by other threads. If the process that holds this reference to the Drive instance is a long running processes (ie indefinite) will the session (?) eventually expire and require authentication again, or are the credentials passed with every request?

The Drive API uses OAuth 2.0 as the authorization mechanism and that involves passing an access token with every request.

Access tokens are short-lived and expire after about 1 hour. When that happens, your application has to request a new access token by using the refresh token that is retrieved the first time the user authorizes the app.

All of this is performed automatically by the Java client library for Google Drive and is documented at https://developers.google.com/drive/about-auth

The documentation also includes a complete Java sample application for Google Drive that you can use as reference:

https://developers.google.com/drive/examples/java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM