Penny Chen
Penny Chen

Reputation: 79

How can I get Google spreadsheets file Id by using Google drive API v3?

I upload a ContactList.csv file to my google drive. When I click to open the CSV file, it will create and open a "ContactList" google spreadsheets file. After I do some edit to it, I need to search this google spreadsheets file to download it as CSV.

What's the mimeTpye should I put in? I tried to use 'text/csv', but it will find the original CSV file, not the google spreadsheets one. Thus I don't know how to get the google spreadsheets file id. Can anyone tell me how to do?

 FileList result= null;
        try {
            result= driveService.files().list()
                    .setSpaces("drive")
                    .setQ(" name contains 'ContactList' and mimeType = 'text/csv' ")

                    .setOrderBy("modifiedTime desc")
                    .execute();

            System.out.println("searchFile ID:"+result.getFiles().get(0).getId());


        }catch (Exception e){
            e.printStackTrace();
        }

enter image description here

Upvotes: 0

Views: 225

Answers (1)

Mateo Randwolf
Mateo Randwolf

Reputation: 2886

According to the documentation, for looking for Google Spreadsheets your MimeType should be application/vnd.google-apps.spreadsheet. Reference to all Google MimeTypes here.

Sample code of how to make this request (documentation here):

  FileList result = driveService.files().list()
      .setQ("name contains 'ContactList' and mimeType='application/vnd.google-apps.spreadsheet'")
      .setOrderBy("modifiedTime desc")
      .setSpaces("drive")
      .setPageToken(pageToken)
      .execute();

Upvotes: 1

Related Questions