Google 드라이브 SDK를 사용하여 Google 드라이브에 파일을 업로드 할 수는 있지만 다운로드가 작동하지 않습니다. Google 드라이브에 해당 콘텐츠의 텍스트를 다운로드하고 읽으려는 문서가 있습니다. 다음 코드로 파일을 가져올 수 있습니다.Google 드라이브 SDK를 사용하여 문서의 콘텐츠를 가져올 수 없습니다.
file = drive.files().get(fileId).execute();
downloadUrl은 항상 null입니다. 어디에서 읽었는지 모르지만 누군가 Google 문서에 downloadUrl이 없으므로 대신 내보내기 링크를 사용해야합니다.
String downloadUrl = driveFile.getExportLinks().get("text/plain");
if (downloadUrl != null && downloadUrl.length() > 0) {
try {
HttpResponse resp =
drive.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
content = new Scanner(resp.getContent()).useDelimiter("\\A").next();
} catch (java.util.NoSuchElementException e) {
return "";
}
}
이 코드를 실행 한 후 내 텍스트 파일의 내용 만이처럼 보이는 무언가의 HTML 표현을하지 않습니다
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to Google Docs</title>
<style type="text/css">
html, body, div, h1, h2, h3, h4, h5, h6, p, img, dl,
dt, dd, ol, ul, li, table, tr, td, form, object, embed,
article, aside, canvas, command, details, fieldset,
....
누군가가 문서의 내용을 읽는 방법을 설명시겠습니까 Google 드라이브에서?
편집 그래서 다운로드가 Google 드라이브 SDK와 함께 작동하도록하는 방법을 알아낼 수 없습니다. 그러나 나는 대신이 코드와 함께 작동하도록 않았다 불량으로
String downloadUrl = driveFile.getExportLinks().get("text/plain");
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(downloadUrl);
get.setHeader("Authorization", "Bearer " + token);
org.apache.http.HttpResponse response = client.execute(get);
InputStream inputStream = response.getEntity().getContent();
content = new java.util.Scanner(inputStream).useDelimiter("\\A").next();
가 나는 드라이브 SDK와 함께 작동하도록 할 필요가 다른 모든 것을 얻을 때. 아무도 이것이 작동하는 이유를 알 수 있지만 SDK와 함께 사용하는 코드가 아니라면 알려주십시오.
@Jerome 다운로드 한 파일을 브라우저에서 열면 내용이 표시되지 않습니다. 대신 읽으려는 실제 텍스트 파일이 다운로드됩니다. – iixi
@OP 업로드가 제대로 진행되고 있는지 확인하십시오. 프로그래밍 방식으로 처리하고 Google 드라이브 웹 UI – Jerome