I am trying to login to a site using a login form and submit button in my app. I have been given the following api information:
the api has been set up at consumer.api.mobodev.terryinc.com
Using this api I am trying to login using a username. The following information has been provided for the api call:
Login with Username The Login with Username service is provided for
existing Consumers to login using their username and password. The
username will be either an email address or mobile phone number
depending on how the Consumer had initially registered. Login with
Username will typically be used when logging into a second or
subsequent Device, or via the browser etc. This is because in the
normal process flow, a Consumer will register and the Access Token
will be returned and cache by the Client Application. The Access
Token is then used when starting the application instead of getting
the Consumer to log in again. Calling the Login with Username logs the
Consumer into the system and creates and returns a valid OAuth Access
Token. The returned OAuth Access Token can then be used in for
subsequent API calls to identify the Consumer of the Client
Application. Attributes
Attribute Value
- Path /v3/logins Support
- Formats JSON, XML HTTP
- Method POST
- Secure No
- Rate Limited
- No Cache
- Timeout TBC
-HTTP Codes 200 – OK
400 – Bad Request.
500 – Internal Server Error.
Below is the code that I have written in the main activity:
HttpClient httpclient = new DefaultHttpClient();
**HttpPost httppost = new HttpPost("consumer.api.mobodev.terryinc.com");**
try {
// Add user name and password
EditText uname = (EditText)findViewById(R.id.username);
String username = uname.getText().toString();
EditText pword = (EditText)findViewById(R.id.password);
String password = pword.getText().toString();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("grant_type","password"));
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
Log.w("Post", "Execute HTTP Post Request");
HttpResponse response = httpclient.execute(httppost);
String str = inputStreamToString(response.getEntity().getContent()).toString();
Log.w("Before Post", str.toString());
My question is did I use the correct url when creating my httpPost object?
Please help as I have no idea how to interpret the api documentation.
In Firefox, there’s this awesome add-on I use to simulate and test API calls – it’s called Rest Client, and I recommend you test the apis here first before you code anything.