I am trying to upvote a question using the Stack Exchange API in android, via the /2.2/questions/{questionID}/upvote route.

But in the log, it's just showing something like:


API link for upvote a question is https://api.stackexchange.com/docs/upvote-question

When I try it from the API doc page it works, but not from my code.

String url= "https://api.stackexchange.com/2.2/questions/"+questionId+"/upvote";

HttpClient httpClient = new DefaultHttpClient ();
HttpPost httpPost = new HttpPost (url.toString () ); 

List<NameValuePair> nameValuePair = new ArrayList<NameValuePair> (2);

nameValuePair.add (new BasicNameValuePair ("key", key) );
nameValuePair.add (new BasicNameValuePair ("access_token", accessToken) );

try {
        httpPost.setEntity (new UrlEncodedFormEntity (nameValuePair) );
} catch (UnsupportedEncodingException e) {
        e.printStackTrace ();
// making request

try {
       response = httpClient.execute (httpPost);
        Log.d ("Http Post Response:", response.toString () );
} catch (ClientProtocolException e) {
        e.printStackTrace ();
} catch (IOException e) {
        e.printStackTrace ();

1 Answer 1


I don't have much experience with HttpClient but the problem does not seem to be caused by your code. Probably it is the lack of required parameters that causes problem. When I called this function in C#, I passed following parameters in order to make it work. I am not sure about "preview" parameter but I believe the site parameter is a must.

Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters.Add("key", APPLICATION_KEY);
parameters.Add("access_token", AccessToken);
parameters.Add("site", SiteApiParameter);
parameters.Add("filter", filter);
parameters.Add("preview", "false");
  • Yes, site is required -- on almost all API calls. preview should be set to true for development and testing. Commented Apr 30, 2015 at 4:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .