Ejemplo n.º 1
0
  public static JSONObject awaitGetGraphMeRequestWithCache(final String accessToken) {
    JSONObject cachedValue = ProfileInformationCache.getProfileInformation(accessToken);
    if (cachedValue != null) {
      return cachedValue;
    }

    GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken);
    GraphResponse response = graphRequest.executeAndWait();
    if (response.getError() != null) {
      return null;
    }

    return response.getJSONObject();
  }
Ejemplo n.º 2
0
  public static void getGraphMeRequestWithCacheAsync(
      final String accessToken, final GraphMeRequestWithCacheCallback callback) {
    JSONObject cachedValue = ProfileInformationCache.getProfileInformation(accessToken);
    if (cachedValue != null) {
      callback.onSuccess(cachedValue);
      return;
    }

    GraphRequest.Callback graphCallback =
        new GraphRequest.Callback() {
          @Override
          public void onCompleted(GraphResponse response) {
            if (response.getError() != null) {
              callback.onFailure(response.getError().getException());
            } else {
              ProfileInformationCache.putProfileInformation(accessToken, response.getJSONObject());
              callback.onSuccess(response.getJSONObject());
            }
          }
        };
    GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken);
    graphRequest.setCallback(graphCallback);
    graphRequest.executeAsync();
  }