Upload to Google Drive without any UI?

2019-01-23 12:09发布

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

4条回答
贪生不怕死
2楼-- · 2019-01-23 12:43

The Google Drive documentation contains the answers you are after:

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

查看更多
霸刀☆藐视天下
3楼-- · 2019-01-23 12:48

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

查看更多
We Are One
4楼-- · 2019-01-23 12:58

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.

查看更多
相关推荐>>
5楼-- · 2019-01-23 12:59
登录 后发表回答