аватар question@mail.ru · 01.01.1970 03:00

How to get user comments left in a particular community in VK

How to get all the comments of a particular user left on the wall under posts in a particular community in VK?

I examined all the methods that exist in the VK API and have not yet found a way to complete this task.

as the source data in this task is given the ID of the ID of the Community.

here is an example I tried to implement:

   for  i  in   range  ( 200 ):  url =  "" https://api.vk.com/method/wall.get?owner_id=%S& ;Offset=%S& ;COUNT=1 "" %(self.text1.toplaintext (), i)  Response = REQUESS.GET (URL) .TEXT PARSED_STRING = JSON.loads (Response)  URL1 =  "" https://api.vk.com/method/wall.getcomments?owner_id=%s& ;Post_id=%S& ;CUNT=100 "" %(self.text1.toplaintext (),,,) PARSED_STRING [ 'response' ] [ 1 ] [] [ 'd' ]) Response1 = REQUESS.GET (URL1) .Text Parsed_String1 = json.loads (response1)   for  j  in   range  ( 1 ,  len  (parade_string1 [ 'response' ])):   if  parsed_string1 [ 'response' ] [j] [ 'items' ] [ 'from_id' ] == Self.text2.toplaintext ():  item1 = qtablewidgetetem (PARSED_STRING1 [] [J] [ 'items' ] [ 'text' ])  item2 = qtablewidgetetem ( str  (Dateetime.Datetime.fromestamp (Parsed_string1 [ 'response' ] [j] [ 'items' ] [ 'data' ]))  self.tablewidget.setitem (I-  1 ,  0 , item1)    self.tablewidget.setitem (I-  1 ,  1 , item2)     

but in this case too frequent server requests are taking place, and this option is too disaster. Tell me, please, in which direction I have to move and what thoughts do you have on this topic.

аватар answer@mail.ru · 01.01.1970 03:00

VK API allows you to get comments only for a specific object for one request. For example, you can get a list of comments on a specific post on the wall using the Wall.getComments method. From this list it will be necessary to select the comments of the right user.

To get comments at once by several posts, you can use the stored procedures, or by the method. The Execute method as a parameter accepts the code of the stored procedure and performs it. VKontakte supports stored procedures with the possibility of up to 25 appeals to the database inside one procedure. Thus, we can get comments at once to several posts at once.

how to write a procedure


for this you can use the functionality that provides VK. First of all, you will need an application for access to the API. You can create it - the button create an application . After the creation, go to editing applications, go to the section of the stored procedures and click add a new procedure

now you need to write the procedure itself. The next procedure will retu the comments of a particular user to 10 posts:

  var owner_id = args.owner_id; var User_id = args.user_id; var offset = Args.offseet; var post_count = args.post_count;   if  (post_count == null)  post_count =  10 ;  // we get the list of the list of the list of post -rustvar posts = API.wall.get ({ : Owner_id,   "" Offseet "" : Offset,  :  100 , }); var i =  0 ; var usercuments = {};   when  (i & lt; posts.items.length & amp; & amp; i & lt; post_count)  { var post_id = posts.items [i].  id ; ; var comments = API.wall.getComments ({ : Owner_id,   "" Postri "" Posta_id "" : post_id,   "Count" ":  100 , });  var j =  0 ;   when  (j & lt; comments.items.length)  {  if  (user_id == null || comments.items [j] .from_id == User_id)    usercMints.push (comments.items [j]);  j = j +  1 ; }  i = i +  1 ; }   retu  usercMints;     

how to cause a stored procedure


we can call in 2 ways:

  • through the previously created application. This is possible only with the help of a token of this application.
  • through the Execute method. A token of any VK application is suitable.

, https://api.vk.com/method/execute.getCommentsfromposts , transmitting the corresponding parameters.

  • in the second to the second to https://api.vk.com/method/execute , transmitting in the quality of the code the contents of the stored procedure.
  • Latest

    Similar