【发布时间】:2021-03-25 01:46:59
【问题描述】:
我正在尝试使用带有 oauth2 凭据的 gmail api 发送,如下所示
private Credential getCredentials(NetHttpTransport httpTransport) throws IOException {
// Load client secrets.
try {
Resource file = resourceLoader.getResource("classpath:credentials.json");
InputStream inputStream = file.getInputStream();
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(inputStream));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline").build();
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
} catch (Exception exception) {
exception.printStackTrace();
LOGGER.info("Exception occured:: {}", exception.getMessage());
throw new RecordNotFoundException(exception.getMessage());
}
}
使用桌面应用的 credentials.json 文件。
当我在开发服务器中部署后,我无法生成访问和刷新令牌保存的文件。
你能帮帮我吗?
【问题讨论】:
-
请编辑您的问题并包含您可能收到的任何错误消息。并定义无法生成的含义。
标签: java google-api google-oauth gmail-api google-api-java-client