有人可以告诉我如何使用Java中的客户端ID和客户端密钥连接到Google Analytics(分析)并提取数据吗?现在,我正在使用json文件来获取数据,并且工作正常,但是在某些情况下,我需要使用客户端ID和客户端密钥从GA提取数据。以下是我如何使用json文件获取数据的代码:
private Analytics initializeAnalyticsReporting() throws GeneralSecurityException, IOException {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
Reader clientSecretReader = new InputStreamReader(new FileInputStream(CLIENT_SECRET_JSON_RESOURCE));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
clientSecrets, AnalyticsScopes.all()).setDataStoreFactory(dataStoreFactory).build();
Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
return new Analytics.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME)
.build();
}