问题描述
我正在使用Google Sheets API来获取Java项目的图纸数据.所有这些都在本地正常工作,但是我正在使用详细权限范围 https://www.googleapis.com/auth/spreadsheets ,其中允许对用户工作表及其属性进行读/写访问.".我希望不向该应用程序提供对我的Google云端硬盘中所有电子表格的访问权限(只是暂时在本地进行此操作).
I'm using the Google Sheets API to obtain sheet data for a Java project. All works as expected locally, but I'm using the verbose permissions scope https://www.googleapis.com/auth/spreadsheets which "Allows read/write access to the user's sheets and their properties.". I would prefer to not provide this app access to all of the spreadsheets in my Google Drive (have only done so locally temporarily).
理想情况下,我想请求使用文件ID对文件进行读/写访问的权限.这可能吗?
Ideally, I'd like to request permission for read/write access to a file using a file's ID. Is this possible?
如果不可能,我猜想 https://www.googleapis.com/auth/drive.file 范围,它提供对应用程序创建或打开的文件的按文件访问".是我能得到的最接近的.我尚未设法找到一种使用此应用程序打开文件的方法.我将如何去做?
If not possible, I'm guessing that the https://www.googleapis.com/auth/drive.file scope which provides "Per-file access to files created or opened by the app." is the closest I can get. I haven't managed to find a way to open the file with this app. How would I go about doing that?
或者如果上述两种解决方案都不理想或不可能,请告诉我您的建议.
Or if both of the above solutions aren't ideal or possible, let me know what you'd recommend.
谢谢!
推荐答案
我知道这是很久以前发布的,但是我会给出答案,以帮助将来的开发人员解决此问题.
I know this was posted quite a while ago, but I'll give my answer to help out future developers coming across this in the future.
我认为使用服务帐户将为您提供您在此处寻找的功能.服务帐户有点像"bot"用户,用户可以与他们共享文档,然后您的服务器可以登录到该服务帐户以访问那些文档.不必要求访问用户的整个Google驱动器或Google表格,您可以让他们手动与您共享文档,我认为对于大多数用户来说,它们会更舒适.
I think using service accounts would give you the functionality you are looking for here. Service accounts are kind of like "bot" users that users can share documents with, and then your server can login to this service account to access those documents. Instead of having to request access to a user's entire google drive or google sheets, you can have them share the documents with you manually, which I think would be more comfortable for most users.
这里是一个例子关于如何在Node.js中进行设置的方法,但是这些想法应该可以很容易地转化为Java.
Here is an example of how to set this up in Node.js, but the ideas should translate fairly readily to Java.
这篇关于使用Google表格/Google云端硬盘API请求特定的文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!