1 package org.average.whereami;
3 import org.average.whereami.PersistentStore;
5 import com.google.api.client.extensions.android2.AndroidHttp;
6 import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
7 import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
8 import com.google.api.client.http.HttpResponseException;
9 import com.google.api.client.http.HttpTransport;
10 import com.google.api.client.http.javanet.NetHttpTransport;
11 import com.google.api.client.json.JsonFactory;
12 import com.google.api.client.json.jackson.JacksonFactory;
14 import android.content.res.Resources;
15 import android.util.Log;
19 final String TAG = getClass().getName();
21 public HttpTransport httpTransport;
22 public JsonFactory jsonFactory;
24 public GoogleAccessProtectedResource accessProtectedResource;
26 public String authErrorMessage;
28 public Oracle(final Resources res, final PersistentStore store) {
29 authErrorMessage = res.getString(R.string.autherror);
31 httpTransport = AndroidHttp.newCompatibleTransport();
32 jsonFactory = new JacksonFactory();
33 AccessTokenResponse token = store.readTokens();
34 Log.v(TAG, "tokens - access: \"" + token.accessToken +
35 "\", refresh: \"" + token.refreshToken +
36 "\", client_id: \"" + ClientCredentials.CLIENT_ID +
37 "\", client_secret: \"" +
38 ClientCredentials.CLIENT_SECRET +
40 accessProtectedResource = new GoogleAccessProtectedResource(
41 token.accessToken, httpTransport, jsonFactory,
42 ClientCredentials.CLIENT_ID,
43 ClientCredentials.CLIENT_SECRET,
47 public void onAccessToken(
49 Log.v(TAG, "Update access token to \""
50 + accessToken + "\"");
51 store.updateAccessToken(
57 public String getResult() {
58 return "<need to be overriden>";