1

I am playing with instagram api endpoints.

Their call sample is:

curl -X DELETE https://api.instagram.com/v1/media/{media-id}/likes?access_token=ACCESS-TOKEN

I am trying to make the call from my android app like this:

URL url = new URL(myBuiltUrl);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setRequestMethod("DELETE");
httpsURLConnection.setDoInput(true);
httpsURLConnection.setDoOutput(false);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpsURLConnection.getOutputStream());
outputStreamWriter.write("access_token=" + token);
outputStreamWriter.flush();
String response = streamToString(httpsURLConnection.getInputStream());

The error I get while running this code is:

java.net.ProtocolException: method does not support a request body: DELETE

How can I fix my code to work correctly ?

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Alin
  • 14,809
  • 40
  • 129
  • 218

1 Answers1

1

Try putting your access_token on your URL, as you are doing with your curl command, and getting rid of the outputStreamWriter stuff.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491