How to use Google Drive in a Java Desktop app?

2019-03-20 06:07发布

问题:

I am dealing with mobile and desktop applications. I am trying to use Google Drive as a permanent storage folder. Unfortunately I am at a loss because I cannot find any examples. Can someone point me at an example of storing or retrieving a file from Google Drive?

I would really like to see a simple example in code or maybe a library which can handle this. I am stuck at Retrieve and Use OAuth 2.0 Credentials https://developers.google.com/drive/credentials

回答1:

Did you look at the sample app on the drive API page?

edit

google moved the examples to github



回答2:

I don't know if I figured out your problem. What I have understood is that you are looking for a way that makes you able to work on the same project from different computers.

If so, you simply have to download Drive. Once install it will ask you what folder you want to keep syncronized with Drive. If you select your workspace, it will be syncronized with Drive. So, on another pc, if you have installed Drive, you will be able to use the workspace folder too, with the same files.

I hope this is helpful.

Marco



回答3:

You should look into Documents List API.

The Google Drive API & SDK are meant to be a mean to integrate applications into the Web-UI of Google Drive. To protect the security of the user's files, it puts some restrictions to the application developer, like:

  • The app has to be installed from the Chrome Web Store
  • The app can only access files created from the app itself,
  • or files selected by the user using the Google Picker UI.

All these restrictions make the Google Drive API not a good choice for most non-web applications. E.g. installing the app from the Chrome Web Store is probably something you would find cumbersome to request from your users for a mobile or desktop application. Nonetheless, without being installed from the Chrome Web Store your application will always receive an error when accessing a file from Google Drive.

The Documents List API allows you to store and load files (not only Google Documents!) into Google Drive.



回答4:

This question is a little bit old, still. You can look at this example: https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2

They do the OAuth2 for accessing task. But I just used the same code to access the files using the v2 API. http://code.google.com/p/google-api-dotnet-client/wiki/APIs#Drive_API

I only retrieved the file list, but it is working (from .NET, desktop app).