SUCCESS!!!
I'm able to access my Google Analytics data now. Here's the JSON result (same result I got from Google's OAuth Playground):
Just for the record, to resolve the issue, I upgraded to spring-security-oauth2 1.0.0.BUILD-SNAPSHOT (which is supposedly for RC1).Code:{"message":["{\"kind\":\"analytics#gaData\",\"id\":\"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXXX&metrics=ga:visits,ga:bounces&start-date=2009-04-20&end-date=2012-05-20&start-index=1&max-results=1000\",\"query\":{\"start-date\":\"2009-04-20\",\"end-date\":\"2012-05-20\",\"ids\":\"ga:XXXXXX\",\"metrics\":[\"ga:visits\",\"ga:bounces\"],\"start-index\":1,\"max-results\":1000},\"itemsPerPage\":1000,\"totalResults\":1,\"selfLink\":\"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXX&metrics=ga:visits,ga:bounces&start-date=2009-04-20&end-date=2012-05-20&start-index=1&max-results=1000\",\"profileInfo\":{\"profileId\":\"XXXXXX\",\"accountId\":\"XXXXXX\",\"webPropertyId\":\"UA-XXXXXX-1\",\"internalWebPropertyId\":\"XXXXXX\",\"profileName\":\"skram\",\"tableId\":\"ga:XXXXXX\"},\"containsSampledData\":false,\"columnHeaders\":[{\"name\":\"ga:visits\",\"columnType\":\"METRIC\",\"dataType\":\"INTEGER\"},{\"name\":\"ga:bounces\",\"columnType\":\"METRIC\",\"dataType\":\"INTEGER\"}],\"totalsForAllResults\":{\"ga:visits\":\"409949\",\"ga:bounces\":\"292510\"},\"rows\":[[\"409949\",\"292510\"]]}"],"success":true}
Since the build is not available from the usual repositories, I had to download the source from GitHub at https://github.com/SpringSource/spring-security-oauth. Then I imported the project into STS (Eclipse). Then I run a mvn install -DskipTests (to bypass the test). I had m2eclipse installed with STS for easy Maven integration.
For future readers, here's my Maven snippet:
spring-oauth.xmlCode:<dependency> <groupId>org.springframework.security.oauth</groupId> <artifactId>spring-security-oauth2</artifactId> <version>1.0.0.BUILD-SNAPSHOT</version> </dependency>
ControllerCode:<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:oauth="http://www.springframework.org/schema/security/oauth2" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd"> <oauth:client id="oauth2AuthenticationClientFilter"/> <oauth:resource id="oauth-resource" client-authentication-scheme="form" type="authorization_code" access-token-uri="https://accounts.google.com/o/oauth2/token" user-authorization-uri="https://accounts.google.com/o/oauth2/auth" client-id="XXXXXX" client-secret="YYYYYY" scope="https://www.googleapis.com/auth/analytics.readonly" pre-established-redirect-uri="http://localhost:8080/myappgoogle/test"/> <oauth:rest-template id="oauth-rest-template" resource="oauth-resource"/> </beans:beans>
By the way, the GA data is taken from my blog at http://krams915.blogspot.com (Spring-related tutorial blog)Code:@RequestMapping(value = "/test") public @ResponseBody StatusResponse test() { String dataUri = "https://www.googleapis.com/analytics/v3/data/ga?" + "ids=ga:XXXXXX&" + "start-date=2009-04-20&" + "end-date=2012-05-20&" + "metrics=ga:visits,ga:bounces"; ObjectNode result = oauth2RestTemplate.getForObject(dataUri, ObjectNode.class); return new StatusResponse(true, result.toString()); }


Reply With Quote