2014-05-24 3 views
0

Java를 사용하여 Google 드라이브 계정에 파일을 업로드하려고합니다. 파일이 업로드되었지만 경고가 표시됩니다 : 경고 : 응용 프로그램 이름이 설정되지 않았습니다. 빌더 # setApplicationName을 호출하십시오. 응용 프로그램 이름이 설정되지 않은 :경고를 받고 Java를 사용하여 Google 드라이브에 파일 업로드

코드 출력이 2014년 5월 24일 오전 11시 59분 14초의 com.google.api.client.googleapis.services.AbstractGoogleClient 경고 입니다

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Arrays; 

import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; 
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; 
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse; 
import com.google.api.client.http.FileContent; 
import com.google.api.client.http.HttpTransport; 
import com.google.api.client.http.javanet.NetHttpTransport; 
import com.google.api.client.json.JsonFactory; 
import com.google.api.client.json.jackson2.JacksonFactory; 
import com.google.api.services.drive.Drive; 
import com.google.api.services.drive.DriveScopes; 
import com.google.api.services.drive.model.File; 


public class UploadFileGoogleDrive { 
     private static String CLIENT_ID = "*****"; 
     private static String CLIENT_SECRET = "******"; 
     private static String REDIRECT_URI = "****"; 

    public static void main(String[] args) throws IOException{ 
     HttpTransport httpTransport = new NetHttpTransport(); 
     JsonFactory jsonFactory = new JacksonFactory(); 

     GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
      httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET, Arrays.asList(DriveScopes.DRIVE)) 
      .setAccessType("online") 
      .setApprovalPrompt("auto").build(); 

     String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build(); 
     System.out.println("Please open the following URL in your browser then type the authorization code:"); 
     System.out.println(" " + url); 
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
     String code = br.readLine(); 

     GoogleTokenResponse response = flow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute(); 
     GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response); 

     //Create a new authorized API client 
     Drive service = new Drive.Builder(httpTransport, jsonFactory, credential).build(); 

     //Insert a file 
     File body = new File(); 
     body.setTitle("My document"); 
     body.setDescription("A test document"); 
     body.setMimeType("text/plain"); 

     java.io.File fileContent = new java.io.File("document.txt"); 
     FileContent mediaContent = new FileContent("text/plain", fileContent); 

     File file = service.files().insert(body, mediaContent).execute(); 
     System.out.println("File ID: " + file.getId()); 
    } 

} 

입니다 . 빌더 # setApplicationName을 호출하십시오. 파일 ID : 우리의 서버 로그에 대한 요청을 해결할 때 사용하기 위해 클라이언트를 구성 할 때 1Ze77mqHtKWDU3eVljATlHQ0U

답변

0

자바에 대한 구글의 API 클라이언트 라이브러리가 강력하게 권장 응용 프로그램 이름을 설정합니다. Google Drive Java command line sample에서 응용 프로그램 이름을 설정하는 방법에 대한 예를 볼 수 있습니다.

관련 문제