Dave Torr
Dave Torr

Reputation: 25

Google Drive PHP v3 API File Metadata

Google specifies the metadata in https://developers.google.com/drive/api/v3/reference/files#resource.

If I do

$parameters['fields']="*";
$files = $service->files->listFiles($parameters);

Then I indeed get pretty much all that. If I just do

$files = $service->files->listFiles($parameters);

i.e. no fields setting I get a subset, but some fields such as createdTime are now blank - and that is one I need. Google recommend (https://developers.google.com/drive/api/v3/fields-parameter) listing only the fields you need to improve performance, but just about everything I put in fields gets an error "Invalid field selection" (tested in https://developers.google.com/drive/api/v3/reference/about/get?apix_params=%7B%22fields%22%3A%22createdTime%22%7D)

$parameters['fields']="name,parents,mimeType,filesize,createdTime,modifiedTime";
$files = $service->files->listFiles($parameters);

Any clues as to how this works? Thanks

Upvotes: 1

Views: 620

Answers (1)

Tanaike
Tanaike

Reputation: 201553

I believe your goal as follows.

  • You want to retrieve the file list using name,parents,mimeType,filesize,createdTime,modifiedTime using Drive API v3 with googleapis for php.

Modification points:

  • There is no fields of filesize. In this case, it's size.
  • When the field values of name,parents,mimeType,size,createdTime,modifiedTime are set for the method of "Files: list" of Drive API v3, please use files(name,parents,mimeType,size,createdTime,modifiedTime). I think that the reason of your error message of Invalid field selection name is due to this.

When above points are reflected to your script, it becomes as follows.

Modified script:

From:
$parameters['fields']="name,parents,mimeType,filesize,createdTime,modifiedTime";
To:
$parameters['fields']="files(name,parents,mimeType,size,createdTime,modifiedTime)";

References:

Upvotes: 2

Related Questions