在Adobe AEM上集成Google Sheets API

问题描述 投票:0回答:1

我正在尝试在Adobe AEM上集成Google Sheets API,我正在阅读文档,但是我对创建凭据对象有一些疑问。这是代码

    private Credential authorize(final NetHttpTransport netHttpTransport) throws GeneralSecurityException, IOException {

            if (jsonKeyObject == null || jsonKeyObject.isEmpty()) {
                throw new GeneralSecurityException("Could not create API Key Json Object");
            }

            // Load client secrets.
            GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new StringReader(getAuthorizationJsonString()));

            // Build flow and trigger user authorization request.
            GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                    netHttpTransport, JSON_FACTORY, clientSecrets, SCOPES)
                    .setDataStoreFactory(new MemoryDataStoreFactory())
                    .setAccessType("offline").build();

            return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
        }

我的问题是,我可以使用其他方式创建凭据对象吗?我不想使用LocalServerReceiver,也不想使用Jetty依赖项,因为我认为AEM上的Dispatcher模块会出现问题。这里的任何输入都会很棒。预先感谢。

java aem google-sheets-api
1个回答
0
投票

我集成了Google工资通行证,为此我使用了GoogleCredential类。

首先获取其中具有私钥的服务帐户并使用下面的代码

JsonFactory jsonFactory = new GsonFactory();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credentials = GoogleCredential.fromStream(getClass().getResourceAsStream("resources/sericeaccountinfo.json"), 
  restMethods.getHttpTransport(), 
                 jsonFactory)
                .createScoped(config.getScopes());

更多详细信息:https://developers.google.com/api-client-library/java/google-api-java-client/oauth2

© www.soinside.com 2019 - 2024. All rights reserved.