我需要创建一个Lotus Notes Java代理,该代理需要将文件夹/文件从本地目录上载到Google Team Drive以进行预定备份。我对用于Java的Google API(https://developers.google.com/api-client-library/java/)进行了一些研究,但是由于我只有Java的基本知识,因此在尝试理解所有这些Java代码时遇到了一些困难。如果我正确理解它,那么api需要一个maven存储库,并且需要定义Lotus Notes中不支持的所有依赖项(不确定这一点,我是否正在阅读正确的文档)。
也许有人可以告诉我这是否可行,并指出要从哪里开始。您可能有一些示例代码,可以用作参考。任何帮助和建议都非常感谢。
谢谢。
答案 0 :(得分:0)
您可能会看到Drive Java Quickstart [1],在这里您将找到如何安装Gradle(与Maven非常相似)以及构建JAVA应用程序以发出请求的步骤的先决条件和链接。到Drive API。
很显然,使用该插件[2]或安装eclipse [3],然后将gradle安装到Lotus Notes中,都不会出现问题。
按照快速入门,Java Drive文档[4]和此google上载文件的指南[5],我成功创建并测试了以下代码:
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
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.client.util.store.FileDataStoreFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import com.google.api.client.http.FileContent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.List;
public class DriveQuickstart {
//General Variables
private static final String APPLICATION_NAME = "Google Calendar API Java Quickstart";
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";
/**
* Global instance of the scopes required by this quickstart.
* If modifying these scopes, delete your previously saved tokens/ folder.
*/
private static final List<String> SCOPES = Arrays.asList(DriveScopes.DRIVE);
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
/**
* Creates an authorized Credential object.
* @param HTTP_TRANSPORT The network HTTP Transport.
* @return An authorized Credential object.
* @throws IOException If the credentials.json file cannot be found.
*/
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
// Load client secrets.
InputStream in = DriveQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline")
.build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
public static void main(String... args) throws IOException, GeneralSecurityException {
// Build the news authorized API client services.
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Drive driveService = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
File fileMetadata = new File();
fileMetadata.setName("Filename");
java.io.File filePath = new java.io.File(“Complete-File-Path”);
FileContent mediaContent = new FileContent("image/jpeg", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute();
System.out.println("File ID: " + file.getId());
}
}
仅提供信息,您可以使用一个工具将所有信息从Lotus Notes迁移到G Suite [6]。
[1] https://developers.google.com/drive/api/v3/quickstart/java
[3] https://www.ibm.com/developerworks/lotus/library/notes-eclipse/
[4] https://developers.google.com/resources/api-libraries/documentation/drive/v3/java/latest/
[5] https://developers.google.com/drive/api/v3/manage-uploads