0
votes

I modified the https://developers.google.com/drive/v2/reference/files/list example to get a list of all file items, using request partial resources.

def retrieve_all_files(service, fields = None):
"""Retrieve a list of File resources.

Args:
    service: Drive API service instance.
    fields: The fields (of each files Resource item!), e.g. 'id,title'
        if not passed, get everything.
Returns:
    List of File resources.
"""
result = []
page_token = None
while True:
    try:
        param = {}
        if fields:
            param['fields'] = 'nextPageToken,items(' + fields + ')'
        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 errors.HttpError, error:
        print 'An error occurred: %s' % error
        break
return result

In my test Drive folder I have a file that has a description string set. When I run

retrieve_all_files(drive_service)

without setting the fields parameter (so get everything), sure enough in the list of items, the file looks fine:

[{u'alternateLink': u'...',...
 u'description': u'Description',
 u'id': u'...',...},...]

but running

retrieve_all_files(drive_service, fields='id,description,title')

yields a list where none of the items have the 'description' property. Not all files have the 'description' property set; is this why the partial resource response is omitting the field even from items that have the property? I'm not sure if this is an undocumented feature that I didn't expect or a bug.

2
To help isolate the problem, could you paste the http request and response. This will help determine if it's a server or client problem. See developers.google.com/api-client-library/python/guide/loggingpinoyyid

2 Answers

1
votes

I was able to reproduce your issue. When using an authorized scopes list of:

https://www.googleapis.com/auth/drive

which should be full access, I was not able to get the description field returned. However, I found that if I also included the scope:

https://www.googleapis.com/auth/drive.appdata

the description field would return properly.

Can you confirm on your end that adding the above to your scopes resolves the issue? Seems like a bug on Google's end.

1
votes

This was confirmed as a bug and a fix should be available in a few days.