I can not figure out how to attach a link in the attachments field
I can not understand in what format to send
there is an object link and it has fields

 url — адрес ссылки; title — заголовок ссылки; description — описание ссылки; image_src — адрес превью изображения к ссылке (если имеется); preview_page — идентификатор wiki страницы с контентом для предпросмотра содержимого страницы, который может быть получен используя метод pages.get. Идентификатор возвращается в формате "owner_id_page_id"; preview_url — адрес страницы для предпросмотра содержимого страницы. 

I understand that you need to make a request in the format attachments = link url_title_description_previewpage_previewurl
I can not figure out what to insert in the preview_page and preview_url fields and whether I understood the request format correctly

`static void makeAComment (String ownerId, String newsId, String textComment, String apiToken, String attachments) throws IOException {

  String requestUrl = "https://api.vk.com/method/wall.addComment?owner_id=" + ownerId + "&post_id=" +newsId+"&text=" +textComment+"&attachments="+attachments+"&access_token=" + apiToken; System.out.println("request url: " + requestUrl); URL obj = new URL(requestUrl); HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); con.setDoOutput(true); int responseCode = con.getResponseCode(); System.out.println("Sending 'GET' request to URL : " + requestUrl); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); System.out.println(response.toString()); }` 
  • At least you would give a link to what you use ... what methods ... and where to look at them ....... and what is it - attachment to a message or to a wall? .... and in general what You specified - these are returned values, and not sent ... Is not it? - Alexey Shimansky
  • @ Alexey Shimansky I make a comment on the post in the group, I want to attach a link and do not get it, I looked at the dock here - vk.com/dev/attachments_w - Sasha
  • write your code, please ..... I want to see what you are doing .... where do you take it and where are you putting it - Aleksey Shimansky
  • @ Alexey Shimansky added the code - Sasha

1 answer 1

No objects are needed, just add the link itself to the attachments as it is and that's it. The described object is not when sending, but when it’s already sent, it will be created by VC itself.

UPD: however, as it turned out, specifically in addComment it does not work, it seems like a bug or a VK bug.

  • @ andreymal request & attachments = linkhttp: //www.address&access_token=token is such a format? - Sasha
  • @Sasha does not need any link either, just attachments=http://www.адрес . Well and, of course, do not forget to escape special characters. - andreymal
  • @ andreymal do as you say, but in response I get attachments should by specified - Sasha
  • @Sasha you put your code in question ... see what you are doing ... Because fortune telling on the coffee grounds has not yet been mastered - Aleksey Shimansky
  • @ Alexey Shimanskiy api.vk.com/method/wall.addComment ? owner_id = -50978521 & post_id = 2468 & from_group = 0 & attachments = https: \ / \ / www.google.com.ua \ /? gws_rd = ssl & ref = as & access_token = 123456789 - Sasha