[英]Google API Drive V3 retrieving drive storage space used
I'm using a google service account to retrieve the usage of data from different users.我正在使用谷歌服务帐户来检索不同用户的数据使用情况。 I'm using google's python client to authenticate and retrieve the data.我正在使用 google 的 python 客户端来验证和检索数据。
Code代码
service = build('drive', 'v3', credentials=auth)
result = service.about().get(email).execute();
result = result.get("storageQuota", {})
I keep getting the following error:我不断收到以下错误:
method() takes 1 positional argument but 2 were given
I want to be able to get it from a specific user's drive information using the email as an identifier.我希望能够使用电子邮件作为标识符从特定用户的驱动器信息中获取它。
The is an undocumented required paramater with that request.该请求是一个未记录的必需参数。 Its called fields.它被称为字段。 I have a bug report out.我有一个错误报告。
service = build('drive', 'v3', credentials=auth)
driveRequest = service.about().get(email);
driveRequest.fields = "*";
result = driveRequest.execute();
result = result.get("storageQuota", {})
Kindly note i am not a python developer this is a guess on how to do it.请注意,我不是 Python 开发人员,这是对如何做的猜测。
Try this snippet example:试试这个片段示例:
result = service.about().get(fields="*").execute()
result = result.get("storageQuota", {})
print(result)
The print
output is: print
输出为:
{'usage': '11638750', 'usageInDrive': '11638750', 'usageInDriveTrash': '7531862'}
If you are an admin and want to get users info, do the next steps:如果您是管理员并且想要获取用户信息,请执行以下步骤:
https://www.googleapis.com/auth/drive
and click Authorize在一个或多个 API 范围中输入https://www.googleapis.com/auth/drive
并单击授权index.py
file with the next code and launch it:使用下一个代码创建index.py
文件并启动它:from googleapiclient.discovery import build
from google.oauth2 import service_account
def main():
SCOPES = ['https://www.googleapis.com/auth/drive']
SERVICE_ACCOUNT_FILE = 'serviceaccountsproject-81ec0d3c1c1c.json'
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
credentials = credentials.with_subject('user@inYourDomain.com')
service = build('drive', 'v3', credentials=credentials)
result = service.about().get(fields="*").execute()
result = result.get("storageQuota", {})
print(result)
if __name__ == '__main__':
main()
And here is an output:这是一个输出:
{'usage': '0', 'usageInDrive': '0', 'usageInDriveTrash': '0'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.