protected long getUserFromAvailableData()
  {
    // if a signed request is supplied, then it solely
    // who the user is.
    JSONObject signed_request = getSignedRequest();
    if (signed_request != null)
    {
      if (signed_request.has("user_id"))
      {
        try
        {
          user = signed_request.getLong("user_id");
        } catch (JSONException e)
        {
          e.printStackTrace();
        }
        setPersistentData("user_id", String.valueOf(user));
        return user;
      }

      // if the signed request didn't present a user id, then invalidate
      // all entries in any persistent store.
      clearAllPersistentData();
      return 0;
    }

    user = Long.valueOf(getPersistentData("user_id", "0"));
    String persisted_access_token = getPersistentData("access_token");

    // use access_token to fetch user id if we have a user access_token, or if
    // the cached access token has changed.
    String access_token = getAccessToken();
    if (access_token != null && access_token != getApplicationAccessToken()
        && (user == 0 || persisted_access_token != access_token))
    {
      user = getUserFromAccessToken();
      if (user != 0)
      {
        setPersistentData("user_id", String.valueOf(user));
      } else
      {
        clearAllPersistentData();
      }
    }

    return user;
  }