While working on Analytics Widget I ran across a bug I was struggeling with for almost ages – until now! ;) A short summary: When using the Google Data API through the GData Java Client Library on Android 1.5 and Android 1.6 you may encounter an “Error authenticating (check service name)” exception while authenticating via Google ClientLogin. Most the time this exception is fired every two logins which is quite suspicious. Unfortunately there was no useful information on the web when searching for the more or less generic error message “check service name”.
That’s why I decided to dig down to the problem today and found out that the problem lies in an empty HTTP response that was supposed to carry session data required for further interaction with the Google server. Resulting from that the HTTP response code retrieved in line 2 is “-1″ hinting at an invalid response code:
[...] int responseCode = urlConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { inputStream = urlConnection.getInputStream(); } else { inputStream = urlConnection.getErrorStream(); } [...]
GoogleAuthTokenFactory.java, Line 564
According to this page the issue is Android related and seems to be fixed in Eclair and later. For everyone else (<= 1.6) the problem can be easily adressed. The only nessecary line that needs to be called before any authentication attempts and that fixes the problem is:
System.setProperty("http.keepAlive", "false");
I didn’t make that up myself but found the idea here. I guess now the HTTP connection to the Google server is closed properly after every authentication attempt resulting in a clean communication between phone and server and therefore solving the problem.
Name (required)
Mail (will not be published) (required)
Website