The seemingly simple code below throws the following error
Traceback (most recent call last): File "search.py", line 48, in pageToken=page_token).execute() File "C:\Users\Choi\AppData\Local\Programs\Python\Python37\lib\site-packages\googleapiclient\discovery.py", line 716, in method
raise TypeError('Got an unexpected keyword argument "%s"' % name) TypeError: Got an unexpected keyword argument "name"
Code:
scope = 'https://www.googleapis.com/auth/drive'
credentials = ServiceAccountCredentials.from_json_keyfile_name('pyGD-eadb4d7ba057.json', scope)
http = credentials.authorize(httplib2.Http())
drive_service = discovery.build('drive', 'v3', http=http)
page_token = None
print('While START::::')
while True:
response = drive_service.files().list(name = 'hello',
spaces='drive',
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
for file in response.get('files', []):
#Process change
print('RESULT::::')
print ('Found file: %s (%s)' % (file.get('name'), file.get('id')))
page_token = response.get('nextPageToken',None)
if page_token is None:
break
What am I doing wrong please? Thank you.
list()
call does not have aname
argument. - Klaus D.name
cannot be directly used to the request body ofdrive_service.files().list()
. If you want to retrieve files which have the filename ofhello
, modify fromname = 'hello'
toq='name = \'hello\''
. If you want to retrieve files which includehello
in the filename, modify fromname = 'hello'
toq='name contains \'hello\''
. If you want to retrieve files which includehello
in the contents, modify fromname = 'hello'
toq='fullText contains \'"hello"\''
. The document of aboutq
is here. - Tanaike