문제
모든 파일을 정렬 할 필요없이 루트 디렉토리에있는 파일 및 폴더 목록을 얻고 싶습니다.이 작업을 수행 할 쿼리가 있습니까?
해결책
루트 폴더는 "root"라는 특수 별칭으로 해결할 수도 있으므로 다음 쿼리가있는 루트의 모든 파일 및 폴더를 가져올 수 있습니다.
https://www.googleapis.com/drive/v2/files?q='root' in parents
.
클라이언트 라이브러리 중 하나를 사용하지 않는 경우 URL을 이스케이프 (자동으로 처리)합니다.
검색 쿼리 언어에 대한 자세한 내용은 https://developers.google.com/drive/search-parameters를 확인하십시오.
다른 팁
이 코드는 루트 디렉토리 의 모든 파일과 폴더를 표시합니다.이 코드를 복사하여 붙여 넣으면 모든 루트의 파일과 폴더를 가져옵니다.
List<File> result = new ArrayList<File>();
Files.List request = null;
try {
request = mService.files().list();
FileList files = request.setQ("'root' in parents and trashed=false").execute();
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
}
catch (IOException e)
{
System.out.println("An error occurred: " + e);
request.setPageToken(null);
}
//Print out all the files and folder of root Directory
for(File f:result)
{
System.out.println("recvd data are: "+f.getTitle());
}
. Google 드라이브 v3 참조 설명서 driveClient 객체를 만드는 데 도움이됩니다.
백그라운드 스레드 (Android)에서 아래 메소드를 실행합니다.
참고 : 필수 범위 권한 "DRIVESCOPES.Drive"
protected String[] getListChildren(String parentId) throws Exception {
String[] children = null;
parentId = parentId == null ? "root" : parentId;
String fileQuery = "'" + parentId + "' in parents and trashed=false";
FileList files = driveService.files().list().setQ(fileQuery).execute();
List<String> fileNames = new ArrayList<String>();
for (File file : files.getFiles()) {
fileNames.add(file.getName());
}
children = fileNames.toArray(new String[0]);
return children;
}
. 제휴하지 않습니다 StackOverflow