How to put like using API from Vkontakte? part of the code that I have written:

final int item_id = 0; final String type = "post"; final String owner_id = "135088235"; final double vers = 5.60; final String sity = "https://vk.com/idcyperxaker?w=wall135088235_9347"; final VKApiPost post = new VKApiPost(); setLike("post", "135088235", post.id); public static String setLike(String type, String owner_id, int item_id ) { final String[] res = {""}; VKRequest request = new VKRequest("likes.add", VKParameters.from("type", type, "owner_id", owner_id, "item_id", item_id)); request.executeSyncWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); try { JSONObject jsonObject = response.json.getJSONObject("response"); res[0] = jsonObject.getString("likes"); } catch (JSONException e) { e.printStackTrace(); }} }); return res[0]; } 

1 answer 1

 public static String setLike(String type, String owner_id, int item_id ) { final String[] res = {""}; VKRequest request = new VKRequest("likes.add", VKParameters.from("type", type, "owner_id", owner_id, "item_id", item_id)); request.executeSyncWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); try { JSONObject jsonObject = response.json.getJSONObject("response"); res[0] = jsonObject.getString("likes"); } catch (JSONException e) { e.printStackTrace(); }} }); return res[0]; } 

Call this:

 setLike("post", "группа", post.id); 
  1. "post" means that we like the Post in the ribbon 2. The group is indicated with a "-" sign, for example: "- 135088235"
  2. post we take from VkAPiPost and each entry goes by id, this means that we like a specific entry in the feed

3 variables needed: String type, String owner_id, int item_id

  • post.id, created an object, and how to use it? those. something needs to be put into it, but what? - Igor Kondaurov
  • VKApiPost do you have? - sviter-pro
  • show your code - sviter-pro
  • final int item_id = 0; final String type = "post"; final String owner_id = "135088235"; final double vers = 5.60; final String sity = " vk.com/idcyperxaker?w=wall135088235_9347 "; final VKApiPost post = new VKApiPost (); setLike ("post", "135088235", post.id); - Igor Kondaurov
  • Update your question with the code ... nothing is clear - sviter-pro