我想使用python和文件ID从Google驱动器下载文件。我有ID,并且文件不可通过链接共享。因此,访问仅限于我。用什么方法下载这样的文件。
#downdrive.py
from pydrive.drive import GoogleDrive
from pydrive.auth import GoogleAuth
# For using listdir()
import os
# Below code does the authentication
# part of the code
gauth = GoogleAuth()
# Creates local webserver and auto
# handles authentication.
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
fid_list=[]
# open file and read the content in a list
with open('gdrivefileid.txt', 'r') as filehandle:
for line in filehandle:
# remove linebreak which is the last character of the string
currentPlace = line[:-1]
# add item to the list
fid_list.append(currentPlace)
f = drive.CreateFile({'id': currentPlace})
print('Downloading file %s from Google Drive' % f['title']) # 'hello.png'
f.GetContentFile(f['title']) # Save Drive file as a local file
认证成功后出现以下错误,我只能访问这些文件。
Downloading file client_secrets.json from Google Drive
Downloading file GEFHTBA.epub from Google Drive
Traceback (most recent call last):
File "downdrive.py", line 27, in <module>
f.GetContentFile(f['title']) # Save Drive file as a local file
File "C:\Users\prati\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydrive\files.py", line 211, in GetContentFile
f = open(filename, 'wb')
PermissionError: [Errno 13] Permission denied: 'GEFHTBA.epub'
我意识到这是导致.enub的问题