我正在使用 Google 服务帐户使用 Resumable Method 将视频上传到 Google Drive。python 代码运行良好,但我遇到了 Google 服务帐户存储问题。
Google 服务帐户似乎只能有 15 GB 的存储空间。即使我将视频上传到常规的 Google Drive 文件夹,该视频仍归服务帐户所有。因此,我尝试将视频的所有者转移到其他帐户,但没有成功,错误是bad request. User message: \"You can't yet change the owner of this item. (We're working on it.)
下面是我的 python 代码,它从服务帐户生成访问令牌并执行可恢复上传
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'creds.json',
scopes='https://www.googleapis.com/auth/drive'
)
delegated_credentials = credentials.create_delegated('service_account_email')
access_token = delegated_credentials.get_access_token().access_token
filesize = os.path.getsize(file_location)
# Retrieve session for resumable upload.
headers1 = {"Authorization": "Bearer " + access_token, "Content-Type": "application/json"}
params = {
"name": file_name,
"mimeType": "video/mp4",
"parents": [folder_id]
}
r = requests.post(
"https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable",
headers=headers1,
data=json.dumps(params)
)
location = r.headers['Location']
# Upload the file.
headers2 = {"Content-Range": "bytes 0-" + str(filesize - 1) + "/" + str(filesize)}
r = requests.put(
location,
headers=headers2,
data=open(file_location, 'rb')
)
是否有解决方法或增加 Google 服务帐户的存储限制?
任何建议将不胜感激。谢谢!