I am trying to learn the usage of Google Analytics API. I am following the tutorial provided by "https://developers.google.com/analytics/devguides/config/mgmt/v3/quickstart/service-java" and have copy pasted their code. I have used the following dependency:
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-analytics</artifactId>
<version>v3-rev20190807-1.32.1</version>
But I am facing three problems:
- Cannot resolve method 'initializeAnalytics' in 'HelloAnalytics'
- Cannot resolve symbol 'AnalyticsReporting'
- Incompatible types. Found: 'com.google.api.services.analytics.Analytics', required: 'AnalyticsReporting'
The problems are bring faced in following areas:
private static AnalyticsReporting initializeAnalytic() throws GeneralSecurityException, IOException {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = GoogleCredential
.fromStream(new FileInputStream(KEY_FILE_LOCATION))
.createScoped(AnalyticsScopes.all());
// Construct the Analytics service object.
return new Analytics.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME).build();
}
and
public static void main(String[] args) {
try {
Analytics analytics = initializeAnalytics();
String profile = getFirstProfileId(analytics);
System.out.println("First Profile Id: "+ profile);
printResults(getResults(analytics, profile));
} catch (Exception e) {
e.printStackTrace();
}
}
Kindly let me know if I am making any mistake or if there is any solution available.