private String getUsernameFromContacts(OAuth2Token token) { try { HttpsURLConnection connection = (HttpsURLConnection) new URL(CONTACTS_URL).openConnection(); connection.addRequestProperty("Authorization", "Bearer "+token.accessToken); if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { final InputStream inputStream = connection.getInputStream(); String email = extractEmail(inputStream); inputStream.close(); return email; } else { Log.w(TAG, String.format("unexpected server response: %d (%s)", connection.getResponseCode(), connection.getResponseMessage())); return null; } } catch (SAXException e) { Log.e(TAG, ERROR, e); return null; } catch (IOException e) { Log.e(TAG, ERROR, e); return null; } catch (ParserConfigurationException e) { Log.e(TAG, ERROR, e); return null; } }