Search in sources :

Example 1 with ServerRequestTask

use of com.tinyspeck.glitchhq.ServerRequestTask in project glitch-hq-android by tinyspeck.

the class Glitch method login.

public void login(String emailAddress, String password, final GlitchSessionDelegate delegate) {
    String sURL = "http://api.glitch.com/oauth2/token";
    Vector<BasicNameValuePair> params = new Vector<BasicNameValuePair>(6);
    params.add(new BasicNameValuePair("username", emailAddress));
    params.add(new BasicNameValuePair("password", password));
    params.add(new BasicNameValuePair("grant_type", "password"));
    params.add(new BasicNameValuePair("scope", "write"));
    params.add(new BasicNameValuePair("client_id", "197-764ef7f4f676f4b53819e52ea7cca4c65badf353"));
    params.add(new BasicNameValuePair("client_secret", "584d266525e5d8d7cf17faf9391f0145f12b12c6"));
    new ServerRequestTask(sURL, true, params) {

        protected void onPostExecute(String result) {
            if (result == null) {
                delegate.glitchConnectionError();
                return;
            }
            Log.i("glitch", result);
            if (result.length() == 0) {
                delegate.glitchLoginFail();
                return;
            }
            try {
                JSONTokener tokener = new JSONTokener(result);
                JSONObject jObject = new JSONObject(tokener);
                accessToken = (String) jObject.get("access_token");
                delegate.glitchLoginSuccess();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }.execute();
}
Also used : JSONTokener(org.json.JSONTokener) ServerRequestTask(com.tinyspeck.glitchhq.ServerRequestTask) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JSONException(org.json.JSONException) Vector(java.util.Vector)

Aggregations

ServerRequestTask (com.tinyspeck.glitchhq.ServerRequestTask)1 Vector (java.util.Vector)1 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 JSONTokener (org.json.JSONTokener)1