Created
December 14, 2013 14:31
-
-
Save wikibook/7959829 to your computer and use it in GitHub Desktop.
구글 드라이브에서 특정 디렉터리에 들어 있는 파일에 대한 직접 다운로드 링크 생성하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.io.File dir = new java.io.File("<path>"); | |
for (java.io.File f : dir.listFiles()) { | |
String name = f.getName(); | |
File body = new File(); | |
body.setTitle(name); | |
body.setMimeType("<mimetype>"); | |
FileContent mediaContent = new FileContent("<mimetype>", f); | |
File file = service.files().insert(body, mediaContent).execute(); | |
Permission newPermission = new Permission(); | |
newPermission.setValue("me"); | |
newPermission.setType("anyone"); | |
newPermission.setRole("reader"); | |
service.permissions().insert(file.getId(), newPermission).execute(); | |
System.out.print(f.getName()); | |
System.out.println("https://docs.google.com/uc?export=download&id=" + file.getId()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment