@Override public void onResume() { super.onResume(); LinkedIdWizard wizard = (LinkedIdWizard) getActivity(); mFingerprint = wizard.mFingerprint; mMasterKeyId = wizard.mMasterKeyId; final String oAuthCode = wizard.oAuthGetCode(); final String oAuthState = wizard.oAuthGetState(); if (oAuthCode == null) { Log.d(Constants.TAG, "no code"); return; } final String gistText = GithubResource.generate(wizard, mFingerprint); Log.d(Constants.TAG, "got code: " + oAuthCode); new AsyncTask<Void, Void, JSONObject>() { @Override protected JSONObject doInBackground(Void... dummy) { try { long timer = System.currentTimeMillis(); JSONObject params = new JSONObject(); params.put("client_id", "7a011b66275f244d3f21"); params.put("client_secret", "eaced8a6655719d8c6848396de97b3f5d7a89fec"); params.put("code", oAuthCode); params.put("state", oAuthState); JSONObject result = jsonHttpRequest("https://github.com/login/oauth/access_token", params, null); // ux flow: this operation should take at last a second timer = System.currentTimeMillis() - timer; if (timer < 1000) try { Thread.sleep(1000 - timer); } catch (InterruptedException e) { // never mind } return result; } catch (IOException e) { Log.e(Constants.TAG, "error in request", e); } catch (JSONException e) { throw new AssertionError("json error, this is a bug!"); } return null; } @Override protected void onPostExecute(JSONObject result) { super.onPostExecute(result); Log.d(Constants.TAG, "response: " + result); if (result == null || !result.has("access_token")) { mStatus1.setDisplayedChild(3); return; } mStatus1.setDisplayedChild(2); step2PostGist(result.optString("access_token"), gistText); } }.execute(); }