I want to be able to retrieve a users calendar and events from the Google Calendar API. Basically I managed to get an Auth-Token from Android’s AccountManager and do the request, but I get
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
As a response. The code producing it is (partial). When running this for the first time, Android asked me to authorize Access to my calendar data for my app, which I accepted.
final Account account = manager.getAccountsByType("com.google")[0];
AccountManagerFuture<Bundle> accountManagerFuture =
manager.getAuthToken(account, "cl", true,
new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bundle = future.getResult();
if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
final String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
final Uri usersCalendars = Uri.parse(
"https://www.googleapis.com/calendar/v3/users/me/calendarList")
.buildUpon()
.appendQueryParameter("key","--myapikey--")
.build();
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(usersCalendars.toString());
request.setHeader("Authorization","GoogleLoginAuth=" + authToken);
request.setHeader("GData-Version","3.0");
HttpResponse response = client.execute(request);
// outputting response, logging etc
As you can see I am not using the google-api-java-client, because I could not get that one to fly either. Basically the example code calls methods that do not exist anymore / are moved to Android’s AccountManager and the android-calendar-example produced a 401 eror instead of listing my calendars.
If you guys have any hints, documentation etc. I’d be glad.
edit I just tried invalidating the token via
manager.invalidateAuthToken("com.google",authToken);
then retrieving a new one via, with the same result.
There is a space in b/w the Authorization header value –
"GoogleLogin auth=xxxxxxx".