Upload to Google Drive without any UI?

2019-01-23 12:06发布

问题:

I am looking to write a server application to upload files to Google Drive. I was previously using the Documents List API, but I see that is deprecated. I'd like to move to the Google Drive API, but that seems very restricted to using a web/OAuth flow.

All I need to do is upload Word, Excel files etc. to Google Drive, but I need to do this in an entirely automated manner, with no user interface of any kind. I wish to write a command line application, which can run on cron or whatever, and not require human intervention via the web etc.

I'd rather move away from Documents List API, as I don't want to get burned when they eventually turn it off, I'd like to use a supported API which Google are not going get rid of any time soon. Does this exist?

Thanks

Garry

回答1:

Your application needs the user's permission to use the API against his files. That authorisation needs to happen using web based Oauth. The result of that authorisation is your server app ends up with a refresh token, which it can store. At any time, your app can convert that refresh token to an access token and access the drive files.

So, provided you accept that you need to do a one-time authorisation, you can achieve what you are looking for.



回答2:

Win/Lin/Mac/... https://github.com/prasmussen/gdrive

$ gdrive list
Go to this url... enter the oauth verification code... OK
$ gdrive upload file
$ gdrive mkdir UploadDir
ID_of_UploadDir
$ gdrive sync upload LocalDir ID_of_UploadDir



回答3:

The Google Drive documentation contains the answers you are after:

https://developers.google.com/drive/v2/reference/files/insert



回答4:

http://www.maketecheasier.com/access-sync-google-drive-in-ubuntu/2012/06/06 i presume this is what your looking for.