Simple API for myBasis http://mybasis.com/
This is simple API for retrieve data about your basis!!
you need Only your username and password, IT DO NOT KEEP TRACE OF YOUR PERSONAL INFORMATIONS (at the end of request every cookie and personal informations will be delete)
Every request it's made with post request. In post request you have to specify username and password
- username : specify your username [string]
- password : your password [string]
- start_date : start date (YYYY-MM-dd) [string]
- end_date : end date (if you want only one day start_date and end_date keep same value) (YYYY-MM-dd) [string]
- interval : Interval of time (in seconds) [Int]
- steps : false or true if you want it [string]
- calories : false or true if you want it [string]
- heartrate : false or true if you want it [string]
- gsr : false or true if you want it (galvanic skin response)[string]
- skin_temp : false or true if you want it [string]
- bodystates : false or true if you want it [string]
Async task to retrieve info
classMyAsyncTaskextendsAsyncTask<String, Integer, String> {
staticInputStreamis = null;
@OverrideprotectedStringdoInBackground(String... params) {
// TODO Auto-generated method stubLog.d("PARAM", params[0]+ " " + params[1]);
returnpostData(params[0], params[1]);
}
protectedvoidonPostExecute(Stringresult) {
try {
JSONObjectjson = newJSONObject(result);
Log.d("JSON-RESULT", json.getString("status"));
JSONObjectmetrics = json.optJSONObject("metrics");
Log.d("JSON-RESULT", metrics.getString("heartrate"));
} catch (JSONExceptione) {
// TODO Auto-generated catch blocke.printStackTrace();
}
}
// protected void onProgressUpdate(Integer... progress) {// pb.setProgress(progress[0]);// }publicStringpostData(Stringuser, Stringpass) {
// Create a new HttpClient and Post HeaderHttpClienthttpclient = newDefaultHttpClient();
HttpPosthttppost = newHttpPost("http://<YOUR_DOMAIN>/loginMyBasis.php");
try {
// Add your dataList<NameValuePair> nameValuePairs = newArrayList<NameValuePair>();
nameValuePairs.add(newBasicNameValuePair("username",user));
nameValuePairs.add(newBasicNameValuePair("password",pass));
nameValuePairs.add(newBasicNameValuePair("start_date","2014-01-18"));
nameValuePairs.add(newBasicNameValuePair("end_date","2014-01-18"));
nameValuePairs.add(newBasicNameValuePair("heartrate","true"));
nameValuePairs.add(newBasicNameValuePair("gsr","true"));
httppost.setEntity(newUrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post RequestHttpResponseresponse = httpclient.execute(httppost);
HttpEntityhttpEntity = response.getEntity();
is = httpEntity.getContent();
} catch (ClientProtocolExceptione) {
// TODO Auto-generated catch block
} catch (IOExceptione) {
// TODO Auto-generated catch block
}
try {
BufferedReaderreader = newBufferedReader(newInputStreamReader(
is, "iso-8859-1"), 8);
StringBuildersb = newStringBuilder();
Stringline = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
Log.d("RESULT", sb.toString());
returnsb.toString();
} catch (Exceptione) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
returnnull;
}
}start task
newMyAsyncTask().execute(newString[]{"username", "password"});If you don't have a webserver to put script file you can use mine
http://www.andreacappellotto.com/basis/loginMyBasis.php
Special Thanks to:
- Maicol Zenatti http://it.linkedin.com/in/maicolzenatti
Enjoy it !!!