gpt4 book ai didi

java - Xpage java代码与gmail api交互

转载 作者:行者123 更新时间:2023-11-30 03:14:23 26 4
gpt4 key购买 nike

使用 Domino Designer 9.0.1FP3 如何使用 Gmail API?

尝试了此链接中的示例 Java 代码 https://developers.google.com/gmail/api/quickstart/java没有任何运气如下:

  1. 导入了必要的gmail api .jar最新版本。
  2. 安装的 jre 是 8 并设置 jre 8 路径的构建路径
  3. 编译器 JRE 版本仍然相同,默认为 1.5。

任何帮助将不胜感激。

这是与 gmail api 交互的 java 代理:

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

import lotus.domino.*;

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.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
//import com.google.api.*;
/***/The following lines has error "import can not be resolved". I've imported jar and their sources from gmail .jar file zip***
import com.google.api.services.gmail.*;
import com.google.api.services.gmail.GmailScopes;
import com.google.api.services.gmail.model.*;
import com.google.api.services.gmail.Gmail;





public class JavaAgent extends AgentBase {


public void NotesMain() {
/** Application name. */
final String APPLICATION_NAME =
"Gmail API Java Quickstart";
/** Directory to store user credentials for this application. */
final java.io.File DATA_STORE_DIR = new java.io.File(
System.getProperty("user.home"), ".credentials/gmail-java-quickstart");

FileDataStoreFactory DATA_STORE_FACTORY;

/** Global instance of the JSON factory. */
final JsonFactory JSON_FACTORY =
JacksonFactory.getDefaultInstance();

HttpTransport HTTP_TRANSPORT;

/* Global instance of the scopes required by this quickstart. */
final List<String> SCOPES =
// Arrays.asList(com.google.api.services.gmail.GmailScopes.)//.GMAIL_LABELS);
Arrays.asList(com.google.api.)

try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// (Your code goes here)

} catch(Exception e) {
e.printStackTrace();
}
}

最佳答案

好的,您需要确保 API 实际上可以在 Java 1.6 上运行,正如 Per 提到的那样。

您可以通过多种方式将 jar 添加到 Domino:

<强>1。在JVM ext/lib目录下

这工作得很好 - 只是维护起来很痛苦,因为所有事情都需要在文件系统中完成(也在 Domino Designer 中)。这适用于 XPage 以及代理。

<强>2。将 jar 附加到您的代理/脚本库

这仅适用于在代理(或 Web 服务)中运行的代码。然而,每次调用代码时都会发生内存泄漏(并且 jar 在内部分离)。所以不要使用这个!

<强>3。添加 jar 作为 jar 设计元素

这也应该有效 - 尽管我对此没有太多经验。我担心与上述元素相同的问题 - 但没有证据证明这一点。所以您可能可以很好地使用它 - 只适用于 XPage。

<强>4。将 jar 添加为插件

您可以将 jar 包装到 OSGi 插件中并在服务器范围内部署它(上面的 2 和 3 只使 jar 可供其所在的 NSF 使用)。这是迄今为止我的首选方式。我写了一个article about the details这可以帮助你。

/约翰

关于java - Xpage java代码与gmail api交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32980791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com