0
votes

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.

1
The list() call does not have a name argument. - Klaus D.
name cannot be directly used to the request body of drive_service.files().list(). If you want to retrieve files which have the filename of hello, modify from name = 'hello' to q='name = \'hello\''. If you want to retrieve files which include hello in the filename, modify from name = 'hello' to q='name contains \'hello\''. If you want to retrieve files which include hello in the contents, modify from name = 'hello' to q='fullText contains \'"hello"\''. The document of about q is here. - Tanaike

1 Answers

2
votes

You need to use the trackback. Let's have a look at googleapiclient/discovery.py

def method(self, **kwargs):
# Don't bother with doc string, it will be over-written by createMethod.

    for name in six.iterkeys(kwargs):
        if name not in parameters.argmap:
>>          raise TypeError('Got an unexpected keyword argument "%s"' % name)

The error was raised here. You have a wrong argument called name.

According to the documentation, the query should be in argument q.

response = drive_service.files().list(q="name='hello'",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()