Google 驱动器 v3 java API 以获取服务帐户的配额

Google drive v3 java API to get quota for service account

我想使用 V3 java API 获取 Google 驱动器的配额。

Drive driveService = getDriveService();

driveService.about().get()

return {}

我正在使用服务帐户获取 driveService。谁能告诉我我错过了什么?

服务帐户是否共享父级 gmail 帐户的存储配额?

关于您的第一个问题,基于迁移到 Google Drive API v3 文档:

Full resources are no longer returned by default. Use the fields query parameter to request specific fields to be returned. If left unspecified only a subset of commonly used fields are returned.

您的代码应该是:

service.about().get().setFields("user, storageQuota").execute()

The fields query parameter should be specified for methods which return

关于你的第二个问题,据我所知,即使在 Google Drive、Gmail 和 Google Photos 之间共享 Drive 存储,你的服务帐户也不会使用 Drive 存储配额你的主账户。您可以阅读更多内容 documentation:

Service accounts should only be used for performing delegation where the effective identity is that of an individual user in a domain. Using the service account as a common owner to create many shared documents can have severe performance implications. Additionally, service accounts may not acquire additional storage quota, nor do they act as members of a domain.

您可以将您帐户的文件夹共享到您的服务帐户,以从您的普通帐户获得额外存储空间