我正在使用Google服务帐户来检索不同用户的数据使用情况。我正在使用Google的python客户端进行身份验证和检索数据。
代码
service = build('drive', 'v3', credentials=auth)
result = service.about().get(email).execute();
result = result.get("storageQuota", {})
我不断收到以下错误:
method() takes 1 positional argument but 2 were given
我希望能够使用电子邮件作为标识符从特定用户的驱动器信息中获取它。
这是该请求的未记录必需参数。它称为字段。我有一个错误报告。
service = build('drive', 'v3', credentials=auth)
driveRequest = service.about().get(email);
driveRequest.fields = "*";
result = driveRequest.execute();
result = result.get("storageQuota", {})
请注意,我不是python开发人员,这是如何实现的猜测。
尝试以下代码段示例:
result = service.about().get(fields="*").execute()
result = result.get("storageQuota", {})
print(result)
print
输出是:
{'usage': '11638750', 'usageInDrive': '11638750', 'usageInDriveTrash': '7531862'}
如果您是管理员,并且想要获取用户信息,请执行以下步骤:
https://www.googleapis.com/auth/drive
并单击授权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('[email protected]')
service = build('drive', 'v3', credentials=credentials)
result = service.about().get(fields="*").execute()
result = result.get("storageQuota", {})
print(result)
if __name__ == '__main__':
main()
这是输出:
{'usage': '0', 'usageInDrive': '0', 'usageInDriveTrash': '0'}