Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google API Drive V3检索使用的驱动器存储空间_Python_Google Api_Google Drive Api_Google Api Python Client - Fatal编程技术网

Python Google API Drive V3检索使用的驱动器存储空间

Python Google API Drive V3检索使用的驱动器存储空间,python,google-api,google-drive-api,google-api-python-client,Python,Google Api,Google Drive Api,Google Api Python Client,我使用一个谷歌服务帐户来检索不同用户的数据使用情况。 我正在使用google的python客户端来验证和检索数据 代码 service = build('drive', 'v3', credentials=auth) result = service.about().get(email).execute(); result = result.get("storageQuota", {}) 我不断得到以下错误: method() takes 1 positiona

我使用一个谷歌服务帐户来检索不同用户的数据使用情况。 我正在使用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”,{})
打印(结果)
打印
输出为:

{'usage': '11638750', 'usageInDrive': '11638750', 'usageInDriveTrash': '7531862'}

如何从域中的用户处获取驱动器信息 如果您是管理员,希望获取用户信息,请执行以下步骤:

  • 在中创建项目
  • 创造
  • 转到管理控制台>安全>高级设置>
  • 在“客户名称”中输入您创建的服务帐户的完整电子邮件
  • 在一个或多个API作用域中放入
    https://www.googleapis.com/auth/drive
    然后单击“授权”
  • 返回,选择您的帐户,启用G套件域范围的委派
  • 创建服务帐户密钥(下载为.json)
  • 为您的项目激活驱动器API。转到API和服务>,单击启用API和服务,搜索驱动器并启用它
  • 使用下一个代码创建
    index.py
    文件并启动它:
  • 这是一个输出:

    {'usage':'0','usageandrive':'0','usageandrivetrash':'0'}


    参考:

    我需要能够通过电子邮件或id获取用户的驱动器空间,我相信您的解决方案将只显示经过身份验证的用户的驱动器空间是,因为未经用户许可,您无法获取有关用户空间的任何信息。他们需要先进行身份验证。@Meerfallthedewott请查看我的最新答案您介意将您在这里提到的错误报告链接起来吗?这样每个人都可以跟踪它。谢谢
    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()