简体   繁体   中英

Iterate over Team Drive files Google Drive API JAVA

Just started experimenting with the Google Drive API, I can iterate over my files in My Drive(tested but not in the current code, I am aware of that), but I also want iterate over my Team Drive files and print the names and ID's of each.

A code snippet found below, the result is zero, where I expected an non-zero integer value since I have multiple Team Drives.

public static Drive getDriveService() throws IOException {
    Credential credential = authorize();
    return new Drive.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME)
            .build();
}

public static void main(String[] args) throws IOException {
    // Build a new authorized API client service.
    Drive service = getDriveService();   
    Drive.Files.List tmp = service.files().list();

    System.out.println(tmp.size());        
}

Maybe nice to mention: I am using the Google Drive API V3.

When using Files.list with intent to include teamDrive, there are certain parameters which you need to set to true like include includeTeamDriveItems or the corpora. You can read that in the reference link which includes a Try-it for testing purposes.

You can also try Teamdrives.list .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM