你可以使用 Google Drive API v3 来获取 Google 电子表格文件的文件ID。

huangapple go评论57阅读模式
英文:

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();
            }

你可以使用 Google Drive API v3 来获取 Google 电子表格文件的文件ID。

英文:

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();
        }

你可以使用 Google Drive API v3 来获取 Google 电子表格文件的文件ID。

答案1

得分: 1

根据文档,查找 Google 电子表格应该使用 MimeType 为 application/vnd.google-apps.spreadsheet。所有 Google MimeTypes 的参考在此处

以下是如何进行此请求的示例代码(文档在此处):

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

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):

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

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

<!-- end snippet -->

huangapple
  • 本文由 发表于 2020年9月17日 18:43:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63936355.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定