Question

Previously, in order to use Google Drive service, we are using the following simple username and password login in Desktop application with Google Documents List API

DocsService client = new DocsService(getCloudApplicationName());
client.setUserCredentials(username, password);

As in Google announcement, https://developers.google.com/google-apps/documents-list/, Version 3 of the Google Documents List API has been officially deprecated as of September 14, 2012. It will continue to work as per our deprecation policy, but we encourage you to move to the Google Drive API.

So, in our desktop Swing application, we need to rewrite the code to gain authentication to Google Drive service.

By referring to code example run at console https://developers.google.com/drive/quickstart-java#step_3_set_up_the_sample

Please open the following URL in your browser then type the authorization code:
  https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=888888888888.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive
  1. User need to open up the browser manually.
  2. Key in his username and password.
  3. He will then obtain a special string from browser, where he needs to copy and paste to the console.

enter image description here

I think I can pretty much simply the process, by using a web view component Integrating JavaFX 2.0 WebView into a Swing Java SE 6 Application, so that the above task will be automated.

However, the webview's component previous history session will be destroyed as I close my desktop Swing application. User need to key in his password and username every-time he launch the desktop app.

enter image description here

From official Google Drive app for Windows, I realize it does have the capability to remember the last authentication of the user. User just need to key in his username and password once. He can then use the Google Drive service again and again, even after restarting the computer.

May I know how I can achieve the similar behavior?

Was it helpful?

Solution

You need to permanently store web view's cookies and set them again once you launch the web view again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top