Google云端硬盘API-如何使用域范围内的服务帐户以及如何从域中获取所有文档列表 [英] Google Drive API - How to work with the domain-wide service account and get all document list from domain

查看:56
本文介绍了Google云端硬盘API-如何使用域范围内的服务帐户以及如何从域中获取所有文档列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用我的应用程序的服务帐户来访问域中所有用户的所有文档.我正在按照以下说明进行操作: https://developers.google.com/drive/delegation

I was trying to use the service account of my App to access to all documents of all users in my domain. I was following these instructions: https://developers.google.com/drive/delegation

但是没有用.你能帮我这个忙吗?

But it didn't work. Could you please help me out on this??

这是有问题的代码行

GoogleCredential凭据=新的GoogleCredential.Builder().setTransport(TRANSPORT).setJsonFactory(jsonFactory).setServiceAccountId("SERVICE_ACCOUNT_EMAIL").setServiceAccountPrivateKeyFromP12File(new java.io.File("SERVICE_ACCOUNT_PKCSs(Service.Accounts)(Scope)范围).setServiceAccountUser("abc@xyz.com").build();

它工作正常,但是它应该向我提供该域所有用户的详细信息...而是仅向我提供一个用户帐户.在服务"帐户文档中,它应该能够访问所有该域下的用户数据.

It's working fine, but it should give me details for all the user for this domain... Instead it gives me only for one useraccount.. In the "Service" account doc it says it should be able to access all the user's data under this domain.

已添加范围并为此帐户启用了APIS

Scopes are added and APIS are enabled for this account

推荐答案

我认为文档并不意味着您可以拥有一个服务帐户,并且一次可以访问整个域中的所有文件,因此您需要采取行动通过使用服务帐户 .setServiceAccountUser("abc@xyz.com")代表特定用户.

I don't think the docs meant that you can have a service account and in one go access all the files in the whole domain, you need to act on behalf of a particular user by using the service account .setServiceAccountUser("abc@xyz.com").

该服务帐户为您省去了从各个用户那里请求权限的麻烦.我认为您可以实现所需的唯一方法是使用Admin SDK中的Directory API检索域中的所有用户(请参阅此答案

The service account simply saves you the hassle of having to request permission from individual users. The only way I think you can achieve what you want is to retrieve all the users in the Domain using the Directory API in the Admin SDK (see this answer Listing users using Google Admin SDK in Java) then loop through these users creating a new Credential object by setting the service account user e.g. setServiceAccountUser("blah@blah.com").

然后使用Drive SDK列出每个用户的文件:

Then use the Drive SDK to list the files for each user:

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

这篇关于Google云端硬盘API-如何使用域范围内的服务帐户以及如何从域中获取所有文档列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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