Skip to content

Instantly share code, notes, and snippets.

@iraSenthil
Created June 13, 2013 15:36
Show Gist options
  • Select an option

  • Save iraSenthil/5774698 to your computer and use it in GitHub Desktop.

Select an option

Save iraSenthil/5774698 to your computer and use it in GitHub Desktop.
private void getAccessToken(String authCode) {
String accessTokenUrl = "https://runkeeper.com/apps/token?grant_type=authorization_code&code=%s&client_id=%s&client_secret=%s&redirect_uri=%s";
final String finalUrl = String.format(accessTokenUrl, authCode, CLIENT_ID, CLIENT_SECRET, CALLBACK_URL);
Thread networkThread = new Thread(new Runnable() {
@Override
public void run() {
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(finalUrl);
HttpResponse response = client.execute(post);
String jsonString = EntityUtils.toString(response.getEntity());
final JSONObject json = new JSONObject(jsonString);
String accessToken = json.getString("access_token");
getTotalDistance(accessToken);
} catch (Exception e) {
displayToast("Exception occured:(");
e.printStackTrace();
resetUi();
}
}
});
networkThread.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment