【问题标题】:Python Google Drive storage quotaPython Google Drive 存储配额
【发布时间】:2020-04-18 02:41:03
【问题描述】:

我使用 Google Drive API 和 Python >3.5,我想获得存储配额。

REST API 在这里Link

到目前为止,我的代码如下所示。您能帮我使用服务对象查询 API 吗?

import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

SCOPES = ['https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.metadata']
creds = None

tokenFile = 'path/to/token.pickle'
if os.path.exists(tokenFile):
    with open(tokenFile, 'rb') as token:
        creds = pickle.load(token)

if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())

service = build('drive', 'v3', credentials=creds)

about_metadata = {
'fields': 'storageQuota'
}
#service.about().get(about_metadata)

【问题讨论】:

    标签: python-3.x google-drive-api


    【解决方案1】:
    • 您想从 Drive API v3 中的“About”方法中检索storageQuota
    • 您希望使用 google-api-python-client 和 python 来实现此目的。
    • 您已经能够从 Drive API 获取值。

    如果我的理解是正确的,那么这次修改呢?

    修改脚本:

    当你的脚本被修改时,请进行如下修改。

    从:
    service = build('drive', 'v3', credentials=creds)
    
    about_metadata = {
    'fields': 'storageQuota'
    }
    #service.about().get(about_metadata)
    
    到:
    service = build('drive', 'v3', credentials=creds)
    
    res = service.about().get(fields='storageQuota').execute()
    print(res)
    

    参考:

    如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

    【讨论】:

    • 哇,这正是我一直在寻找的!非常感谢。
    • @Markus 感谢您的回复。很高兴您的问题得到解决。
    猜你喜欢
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多