2

I am trying to list files from my google drive. I am using official copy pasted method from docs, but it doesn't return valid results - it lists also some recently deleted (trashed) files and do not list some recently created files. It looks like it is cached and it take quite a long time (minutes, sometimes even hours) to reflect any changes. Anyone know how to get realtime and valid - not outdated and cached - list of file from google drive? I am using this method:

    // I need to get list of NOT TRASHED files from root directory
    Query query = new Query.Builder().addFilter(Filters.eq(SearchableField.TRASHED, false).build();
    DriveFolder folder = Drive.DriveApi.getRootFolder(mGoogleApiClient);

    MetadataBufferResult filesMetadata = folder.queryChildren(mGoogleApiClient, query).await();

    if (!filesMetadata.getStatus().isSuccess()) {
      log("failed");
      return false;
    }

    Iterator<Metadata> it = filesMetadata.getMetadataBuffer().iterator();

    while (it.hasNext()) {
      Metadata meta = it.next();
        log("File name: " + meta.getTitle() + ", size: " + meta.getFileSize() + ", created: " + meta.getCreatedDate());
    }

    // but this list is outdated, doesn't reflect latest changes
Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
qkx
  • 2,383
  • 5
  • 28
  • 50
  • Yes - I used and old api. New one is not realtime - check my answer in this topic: http://stackoverflow.com/a/26524098/1360930 – qkx Jan 27 '15 at 11:06

1 Answers1

1

Google drive api does not sync immediately after any action so you have to force google drive to sync using the following method call :

Drive.DriveApi.requestSync(_gac);
KeatsPeeks
  • 19,126
  • 5
  • 52
  • 83
Amol Suryawanshi
  • 2,108
  • 21
  • 29
  • 1
    It would be really easy if it worked. but it does not. – seanpj Feb 18 '15 at 16:09
  • I think u are using Google Drive core API. instead core API use Google Drive REST API calls.Core API takes some time to commit changes on Google Drive server so you may get null folder ID. – Amol Suryawanshi Jun 01 '15 at 18:41