Google Drive API访问我自己的帐户 [英] Google Drive API Access my own account

查看:318
本文介绍了Google Drive API访问我自己的帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我的服务器/笔记本电脑上运行一个简单的过程,每天一次将文件上传到我的谷歌驱动器。我不希望分享这个,允许其他用户使用它等。

I wish to run a simple process on my server/laptop that will upload files to my google drive on a daily basis, once a day. I don't wish to share this, allow other users to use it etc.

我发现的所有示例都涉及浏览到地址以获得用户的许可(我),然后得到一个认证代码等等,然后继续

All examples I find seem to involve browsing to an address to gain permission from the user (me) and then getting an auth code etc and proceding

ref: Java quickstart


  1. 有没有一种方法/示例可以在不需要浏览器,每次获取权限都会获得唯一的授权码,因为我只想为我的帐户执行此操作。

  2. 我可以使用带CURL命令的bash脚本而不必使用Java吗?
  3. li>
  1. Is there a way/example to do this without need of a browser, getting permission getting unique auth code each time as I only want to do this for my account?
  2. Can I use a bash script with CURL commands rather than having to use Java?


推荐答案


  1. 是的。见如何我是否在没有用户干预的情况下授权应用程序(网页或已安装)? (canonical?)

是的。如果你的文件很大,并且你正在做可恢复的上传,它会变成一个复杂的脚本,但对于小文件来说,它是完全可行的。你需要玩一下才能得到正确的编码,多部分MIME身体,MIME类型和内容大小,但这一切都非常可行。您将开始使用存储的刷新令牌调用Google的auth api来获取访问令牌。然后,您将该访问令牌设置为授权承载标头,作为您的内容上传呼叫的一部分。

Yes. It becomes a complicated script if your file is large and you are doing resumable uploads, but for small files it's perfectly feasible. You'll need to play around a bit to get the correct encoding, multipart mime body, mime type and content size, but it's all eminently doable. You'll start by calling Google's auth api with your stored refresh token to get an access token. Then you'll set that access token into an Authorization bearer header as part of your content upload call.

这篇关于Google Drive API访问我自己的帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆