code: public TokenResult prepareLogin(String username) throws Exception {
      username = encode(username);
      Api apiResult = null;
      TokenResult token = new TokenResult();
      token.tokenName = "lgtoken";
      token.tokenMode = TokenMode.token1_19;
      // see https://github.com/WolfgangFahl/Mediawiki-Japi/issues/31
      if (this.isVersion128()) {
        apiResult = this.getQueryResult("&meta=tokens&type=login");
        super.handleError(apiResult);
        token.token = apiResult.getQuery().getTokens().getLogintoken();
      } else {
        apiResult = getActionResult("login", "&lgname=" + username, null, null);
        super.handleError(apiResult);
        Login login = apiResult.getLogin();
        token.token = login.getToken();
      }
      return token;
    }
docs: prepare the login by getting the login token
  
  @param username
  @return the ApiResult
  @throws Exception