I am trying to implement a basic data feed example, and all I get is simple:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized.
But when I use http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html
It works great with my Google Analytics account.
It seems that I did everything in accordance with the instructions of OAuth2: created a client identifier and a client secret, included the Analytics API.
I also tried to get my profiles and accounts with the Analytics management API, but I get the same error. What am I doing wrong?
Here is my code (of course, I run this code with the actual CLIENT_ID, CLIENT_SECRET and TABLE_ID):
public class AnalyticsTest { private static final String CLIENT_ID = "MY_CLIENT_ID"; private static final String CLIENT_SECRET = "MY_CLIENT_SECRET"; private static final String REDIRECT_URL = "urn:ietf:wg:oauth:2.0:oob"; private static final String APPLICATION_NAME = "test"; private static final String SCOPE = "https://www.googleapis.com/auth/analytics";
Here is the stack trace:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized use {
"code": 401,
"errors": [{
"domain": "global",
"location": "Authorization",
"locationType": "header",
"message": "Invalid credentials",
"reason": "authError"
}],
"message": "Invalid credentials"
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from (GoogleJsonResponseException.java:138)
at com.google.api.client.googleapis.services.GoogleClient.execute (GoogleClient.java:123)
at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed (JsonHttpRequest.java:67)
at com.google.api.services.analytics.Analytics $ Data $ Ga $ Get.execute (Analytics.java:1335)
in voc.AnalyticsTest.main (AnalyticsTest.java:76)
source share