Search code examples
androidhttp-postinstagram-api

How to like a media via instagram api?Keep getting statusCode = 400


I'm trying to implement instagram media liking on android. This is the endpoint I've to POST to https://api.instagram.com/v1/media/{media-id}/likes Here is what I wrote so far, but it keeps giving me status code = 400.

String url =String.format("%s/media/%s/likes",ConnectionConstants.API_URL, media_id);
            HttpClient httpclient = new DefaultHttpClient();
            final HttpPost postRequest = new HttpPost(url);

            try {
                HttpResponse response =httpclient.execute(postRequest);
                final int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode != HttpStatus.SC_OK) {
                    return null;
                }

                final HttpEntity entity = response.getEntity();
                if (entity != null) {
                    ...
                        return true;
                    }
                }
            } catch (Exception e) {
                postRequest.abort();
            }
return null;
        }

Solution

  • Ok, I've figured out what was wrong. There should be access_url in the end, as part of url

    String url =String.format("%s/media/%s/likes?access_code=%s",ConnectionConstants.API_URL, media_id,access_code);