I'm really at a dead end. I've been trying to figure out how to reach my Gmail-inbox from an Android-app with an existing OAuth2-token that I have received from Google moments before. I can auth myself with a token with this:
URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo?access_token=" +token);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
But it feels like I'm going at this problem at a wrong angle, somehow. I've been trying to decipher Gmail's API but haven't gotten anywhere. Can somebody push me in the right direction here?
Or if the code I posted is correct, how would I proceed from that?
EDIT: So I've figured out how to use Gmail's API to get the latest 100 mails with this code:
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleTokenResponse response = new GoogleTokenResponse();
response.setAccessToken(myExistingToken);
GoogleCredential credential = new GoogleCredential().setFromTokenResponse(response);
Gmail service = new Gmail.Builder(httpTransport, jsonFactory, credential).setApplicationName(myApplicationName).build();
ListThreadsResponse threadsResponse = service.users().threads().list("voxcommunis@gmail.com").execute();
List<com.google.api.services.gmail.model.Thread> threads = threadsResponse.getThreads();
for ( com.google.api.services.gmail.model.Thread thread : threads ) {
Log.d(LOG_TAG, "Thread ID: "+ thread.getId());
}
So I will continue on this path to get new emails some how =)