casolorz
casolorz

Reputation: 9544

How can I get file size and modified date on the V3 Google Drive API?

I'm upgrading from v2 to v3 of the Google Drive API on Android and would like to know how to get some extra fields when I query for files, ideally without paging.

This is the code I got:

FileList result = drive.files().list()
                .setQ("'root' in parents  and trashed=false")
                .setFields("files(id, name, fileSize, modifiedDate, mimeType)")
                .execute();

But it says that invalid field selection fileSize.

Also I would like a way to get a download url for the file that works temporarily for sharing with other apps. This used to be achievable with getDownloadUrl and adding the token on v2.

Thanks.

Edit: Looks like the correct fields are:

            .setFields("files(id, name, size, modifiedTime)")

Upvotes: 3

Views: 5909

Answers (4)

Enes Kayıklık
Enes Kayıklık

Reputation: 589

You can use * to get the all fields of a file.

val files = drive.files().list().setSpaces("appDataFolder")
                .setFields("nextPageToken, files(*)")
                .setPageSize(10)
                .execute()

Upvotes: 0

Reza
Reza

Reputation: 1

modifiedDate did not work for me, although it says on the documents. modifiedTime gives both date and time

$params = array
(
  'pageSize' => 1000,
  'fields' => "nextPageToken, files(id , name , modifiedTime)",
  'q' => "'" . $parent_folder_id . "' in parents"
) ;
$files = $service -> files -> listFiles($params) ;   
foreach ($files as $file)
{
  echo($file -> getModifiedTime()) ;
  echo($file -> getName()) ;
}

Upvotes: 0

Andrew
Andrew

Reputation: 2886

When you get files from a folder:

val files = driveService.files().list()
                    .setSpaces("appDataFolder")
                    .setFields("files(id, name, createdTime)")
                    .execute()

When you create file:

val file = driveService.files().create(fileMetadata, mediaContent)
                    .setFields("id, name, createdTime")
                    .execute()

You can see all available properties here.

Upvotes: 1

Cheticamp
Cheticamp

Reputation: 62831

Evidently files(size) works although I don't see it documented. You can try it here.

I am not so sure about getDownloadUrl. You can check the v2 to v3 conversion documentation at this page. It suggests that files.get with ?alt=media might be a suitable replacement for downloadUrl.

Upvotes: 1

Related Questions