Created
July 11, 2016 12:23
OAuth and REST in Android: Part Two 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HttpClient httpClient = new DefaultHttpClient(); | |
HttpPost httpPost = new HttpPost( | |
"https://api.dailymile.com/entries.json?oauth_token=" | |
+ token); | |
httpPost.setHeader("content-type", "application/json"); | |
JSONObject data = new JSONObject(); | |
data.put("message", dailyMilePost.getMessage()); | |
JSONObject workoutData = new JSONObject(); | |
data.put("workout", workoutData); | |
workoutData.put("activity_type", dailyMilePost.getActivityType()); | |
workoutData.put("completed_at", dailyMilePost.getCompletedAt()); | |
JSONObject distanceData = new JSONObject(); | |
workoutData.put("distance", distanceData); | |
distanceData.put("value", dailyMilePost.getDistanceValue()); | |
distanceData.put("units", dailyMilePost.getDistanceUnits()); | |
workoutData.put("duration", dailyMilePost.getDurationInSeconds()); | |
workoutData.put("title", dailyMilePost.getTitle()); | |
workoutData.put("felt", dailyMilePost.getFelt()); | |
StringEntity entity = new StringEntity(data.toString()); | |
httpPost.setEntity(entity); | |
HttpResponse response = httpClient.execute(httpPost); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment