Fight the Future

Java言語とJVM、そしてJavaエコシステム全般にまつわること

Google AnalyticsのデータをJavaで取得する

		// Service Object to work with the Google Analytics Data Export API.
		AnalyticsService analyticsService = new AnalyticsService("gaExportAPI_acctSample_v2.0");
		// ClientLogin Authorization.
		analyticsService.setUserCredentials(userName, password);

		// Create a query using the DataQuery Object.
		DataQuery query = new DataQuery(new URL("https://www.google.com/analytics/feeds/data"));
		query.setStartDate("2010-01-01");
		query.setEndDate("2010-12-31");
		query.setDimensions("ga:pagePath");
		query.setMetrics("ga:pageviews");
		query.setSort("-ga:pageviews");
		query.setIds("ga:xxxxxxx");

		query.setFilters("ga:pagePath==xxx");

		// Make a request to the API, using DataFeed class as the second parameter.
		DataFeed dataFeed = analyticsService.getFeed(query.getUrl(), DataFeed.class);

		for (DataEntry entry : dataFeed.getEntries()) {
			entry.longValueOf("ga:pageviews");
		}

http://code.google.com/intl/ja/apis/analytics/docs/gdata/2.0/gdataJava.html

http://code.google.com/intl/ja/apis/analytics/docs/gdata/gdataReferenceDataFeed.html

http://code.google.com/intl/ja/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html