我正在尝试获取特定Google驱动器文件夹中文件和文件夹的列表。
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive'
]
credentials = ServiceAccountCredentials.from_json_keyfile_name('creds.json', scope)
service = build('drive', 'v3', credentials=credentials)
我正在使用此功能,但肯定缺少某些内容。请指导!
def retrieve_all_files(service):
result = []
page_token = None
while True:
try:
param = {}
if page_token:
param['pageToken'] = page_token
files = service.files().list(**param).execute()
result.extend(files['items'])
page_token = files.get('nextPageToken')
if not page_token:
break
except:
print('An error occurred')
break
return result