google 드라이브에서 내 계정으로 파일을 업로드하고 싶습니다. 이 프로세스는 사람의 개입없이 수행되어야합니다. 내 사용자와 내 비밀번호를 제공하는 Google 드라이브 API를 사용하여 Google 드라이브에 파일을 업로드 할 수있는 방법이 있습니까?OAuth없이 java로 Google 드라이브에 파일 업로드
내가 지금까지했던 어떤 :
- 내가 https://console.developers.google.com에서
- 을 https://console.developers.google.com에서 프로젝트를 생성하고, 구글 드라이브 API를 사용 -> API를 & 인증을 -> 자격 증명 나는 새로운 클라이언트 ID를 생성 응용 프로그램 유형에서 서비스 계정을 선택하고 pkcs12 키를 다운로드했습니다.
- 나는 다음 코드를 가지고 : 나는 결과가 괜찮 코드를 실행하면
/**
* Email of the Service Account
*/
private static final String SERVICE_ACCOUNT_EMAIL = "[email protected]";
/**
* Path to the Service Account's Private Key file
*/
private static final String SERVICE_ACCOUNT_PKCS12_FILE_PATH = "/path/to/pkcs12/donloaded.pkcs12";
/**
* Build and returns a Drive service object authorized with the service
* accounts.
*
* @return Drive service object that is ready to make requests.
*/
public static Drive getDriveService() throws GeneralSecurityException, IOException, URISyntaxException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
List<String> scopes = new ArrayList<String>();
scopes.add(DriveScopes.DRIVE);
GoogleCredential credential;
credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).build();
return service;
}
public static void main(String[] args) throws GeneralSecurityException, IOException, URISyntaxException {
Drive client = getDriveService();
File body = new File();
body.setTitle("mytitle");
body.setMimeType("application/vnd.google-apps.spreadsheet");
File file = client.files().insert(body).execute();
System.out.println(file.getId());
System.out.println(file.getAlternateLink());
}
, 나는 파일의 ID를 얻을 대체 링크를하지만, 파일 내 계정에로드 할 수 없습니다. 브라우저에 대체 링크를 붙여 넣지 만 권한이 없습니다.
방금 업로드 한 파일은 어디입니까? 내 계정 드라이브까지 표시하려면 무엇을 변경해야합니까? 드라이브와 관련된 사용자 이름과 암호는 어디에 추가해야합니까? 이 파일을 공개하려면 어떻게해야합니까?
관심을 가져 주셔서 대단히 감사합니다. 나는 그들이 나를 도울 수 있기를 바랍니다.