This is the connection piece of code. What am i doing wrong?
HttpURLConnection httpConnection = null;
BufferedReader bufferedReader = null;
StringBuilder response = new StringBuilder();
String msg = "";
try {
URL url = new URL("https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json");
httpConnection = (HttpURLConnection) url.openConnection();
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
httpConnection.setRequestMethod("POST");
String jsonString = auth;
JSONObject jsonObjectDocument = new JSONObject(jsonString);
String token = jsonObjectDocument.getString("token_type") + " "
+ jsonObjectDocument.getString("access_token");
httpConnection.setRequestProperty("Authorization", token);
httpConnection.setRequestProperty("Content-Type",
"application/json");
httpConnection.connect();
StringBuffer json = new StringBuffer();
OutputStreamWriter writer = new OutputStreamWriter(httpConnection.getOutputStream(), "UTF-8");
writer.write(token);
writer.close();
if (httpConnection.getResponseCode() / 100 == 2) { // 2xx code means success
BufferedReader br = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
json.append(line);
}
br.close();
} else {
json.append(httpConnection.getErrorStream());
}
httpConnection.disconnect();
// String line;
// while ((line = bufferedReader.readLine()) != null) {
// response.append(line);
// }
result = json.toString();
} catch (Exception e) {
result = "GET error: \n" + Log.getStackTraceString(e);
} finally {
if (httpConnection != null) {
httpConnection.disconnect();
}