【问题标题】:Checking Gmail account in order to keep track of space been used in percentage with Python检查 Gmail 帐户以跟踪使用 Python 的空间百分比
【发布时间】:2018-09-03 07:16:01
【问题描述】:

使用 Python,我需要读取 Gmail 帐户的总存储量,以跟踪从 Gmail 页面看到的已使用空间百分比。

例如:如果它说 10GB 的 15GB (66%) 比一个文件应该记录数字 - 66。

有可能吗?

提前致谢

【问题讨论】:

    标签: python windows gmail storage


    【解决方案1】:

    您可以使用 requests 库向 Google Drive 的 api 发出基本请求,因为邮件和驱动器共享相同的存储空间。您可以查看API的详细信息 here

    import requests
    import json
    
    def main():
        req = requests.get('https://www.googleapis.com/drive/v3/about?fields=storageQuota&key={YOUR_API_KEY}')
        json_response = json.loads(req.content)
        //Process the json response to your free will
    
    if __name__ == '__main__':
        main()
    

    请求的结果是这样的

    200 OK
    
    - Hide headers -
    
    cache-control:  private, max-age=0, must-revalidate, no-transform
    content-encoding:  gzip
    content-type:  application/json; charset=UTF-8
    date:  Mon, 03 Sep 2018 08:42:33 GMT
    expires:  Mon, 03 Sep 2018 08:42:33 GMT
    server:  GSE
    transfer-encoding:  chunked
    vary:  Origin, X-Origin
    
    {
     "storageQuota": {
      "limit": "16106127360",
      "usage": "15054153867",
      "usageInDrive": "15022609247",
      "usageInDriveTrash": "0"
     }
    }
    

    【讨论】:

    • 感谢您的回复。我在代理后面。我试过很多这样的解决方案: proxies = {"http":"rpy3bpb:password@10.204.68.5:8080"} r = requests.get("example.com", proxies=proxies) 错误是:requests.exceptions.ProxyError: HTTPSConnectionPool( host='www.googleapis.com', port=443): 最大重试次数超过了 url: /drive/v3/about?fields=storageQuota&key=%7BYOUR_API_KEY%7D (由 ProxyError('Cannot connect to proxy.', error ('隧道
    • 您使用的代理可能已被 Google 禁止,因为 API 请求存在限制。您可以使用不同的代理进行检查,但如果该代理还有其他用户,则不可靠。另一个提醒不要忘记在 URL 中更改您的 API 密钥,否则它将返回状态 401 Unauthorized。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 2020-06-15
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    相关资源
    最近更新 更多