우리 모두가 정말로 원하는 기능을 만들었습니다. 다음은 Google 드라이브 폴더 내의 모든 파일과 폴더를 나열합니다. 디렉토리의 모든 파일을 원하는지 아니면 서비스가 디렉토리 내에서 소유하고있는 파일 만 원하는지 지정할 수 있습니다. 날씨는 ids 만 원하거나 파일 이름 만 원하거나 둘 다 원한다면 필요합니다.
Library_GoogleDriveFileList : 나는이 같은 문제를했습니다
import numpy
import pprint
from apiclient import errors
import collections
def Main(
Service = None,
FolderId = None,
ResultFileNamesOnly = False,
ResultFileIdsOnly = True,
IncludeServiceFilesOnly = False,
SortResults = False,
ResultFormat = None,
):
Result = None
if (ResultFormat is None):
ResultFormat = 'list'
if (FolderId == None):
FolderId = 'root'
SearchParameterString = "'" + FolderId + "' in parents"
SearchOwners = None
if (IncludeServiceFilesOnly):
SearchOwners = 'DEFAULT'
else:
SearchOwners = 'DOMAIN'
print 'SearchOwners', SearchOwners
#Because there is a return limit of 460 files (falsly documented as 1000)
# we need to loop through and grab a few at a time with different requests
DriveFileItems = []
PageToken = None
while True:
try:
print 'PageToken', PageToken
DriveFilesObject = Service.files().list(
q = SearchParameterString,
corpus = SearchOwners, #'DOMAIN'
maxResults = 200,
pageToken = PageToken,
).execute()
DriveFileItems.extend(DriveFilesObject['items'])
PageToken = DriveFilesObject.get('nextPageToken')
if not PageToken:
break
except errors.HttpError, error:
print 'An error occurred: %s' % error
break
#print 'DriveFileItems', DriveFileItems
#pprint.pprint(DriveFileItems)
FileNames = []
FileIds = []
for Item in DriveFileItems:
FileName = Item["title"]
FileNames.append(FileName)
FileId = Item["id"]
FileIds.append(FileId)
#print 'FileIds'
#pprint.pprint(FileIds)
if ResultFileNamesOnly == False and ResultFileIdsOnly == False:
if (ResultFormat == 'dict'):
Result = collections.OrderedDict()
for FileName , FileId in zip(FileNames, FileIds):
Result [FileName] = FileId
elif (ResultFormat == 'list'):
Result = numpy.array([FileIds, FileNames]).T.tolist()
elif ResultFileNamesOnly == True and ResultFileIdsOnly == False:
Result = FileNames
elif ResultFileNamesOnly == False and ResultFileIdsOnly == True:
Result = FileIds
elif ResultFileNamesOnly == True and ResultFileIdsOnly == True:
raise Exception('ResultFileNamesOnly == True and ResultFileIdsOnly == True:')
if (ResultFormat == 'list'):#type(Result).__name__ == 'list'):
Result = list(reversed(Result))
if (SortResults):
Result = list(sorted(Result))
#TODO -> more intellegent sort for dict, 2d list
return Result
. 나에게 그것을 고치는 법을 보여 줄 수 있니? 나는 그것을 며칠 동안 찔렀다 – Dolphin
oauth 범위를'https : // www.googleapis.com/auth/drive'로 바꾼다 –
java android와 함께 일하고있다. 나는 그 범위를 어디에서 바꿀 지 모른다. 여기 내 코드가 있습니다. http://pastebin.com/pTFaVs4A – Dolphin