英文:
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();
}
英文:
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();
}
答案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("name contains 'ContactList' and mimeType='application/vnd.google-apps.spreadsheet'")
.setOrderBy("modifiedTime desc")
.setSpaces("drive")
.setPageToken(pageToken)
.execute();
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论