Accessing WebService API from Java/Android

Hello all,

I'd like to post here a example of how to connect and make a post request on the webservice api, more specificaly the method auth.gettoken. The problem I had that make me spend a lot of time trying to fix was, I was able to connect to the API (through HttpClient or HttpURLConnection but I was getting this error: Missing parameter username in method auth.gettoken and it almost drove me crazy.

I've tried to find some examples in Elgg Community, but I wasn't able to find. So now that I find the solution I'd like to share with you guys. So let's go. 

I used the code of this guy:

You'll need the code of inputStreamToString function, but it is here:


public static String inputStreamToString(InputStream is) throws Exception {

BufferedReader reader = new BufferedReader (new InputStreamReader (is));
StringBuilder sb = new StringBuilder();
String line = null;

while ((line = reader.readLine()) != null) {


return sb.toString();


I hope it will help,

Thanks a lot.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking