A
A
Aleksandr R2016-03-30 08:03:52
Python
Aleksandr R, 2016-03-30 08:03:52

How to get the latest comment on a group wall via VK Api?

It is required to check the posts on the wall every 10 minutes and receive it when a new comment appears.
All this is required to be done through the VK API in python.
I know about the method wall.getComment, but I can’t run through all the messages in the loop and look for new comments for output.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander R, 2016-04-06
@alexhouse

I publish my version, which turned out as a result of trial and error:
Written in Python 3 using the VK_api module

while True: #запускаем бесконечный цикл
        man_id = str(-29534144) #id группы с которой будем брать посты и комментарии
        postidlist = vk.wall.get(owner_id=man_id, count=1, offset=0) #получаем последний пост
        a = str(postidlist['items'][0]['id']) #получаем id поста в виде цифры и записываем
        comm = vk.wall.getComments(owner_id=man_id, post_id=a, count=1, sort='desc', offset=0) #Получаем последний комментарий
com_text = comm['items'][0]['text'] #вытаскиваем из полученного ответа только текст
       print(com_text) #выводим комментарий
         time.sleep(5) #засыпаем на 5 секунд

If someone has a more accurate option, then I will be glad.

A
Alexey, 2016-03-30
@RusTech

What doesn't work? Write a script - to freelancers, suggest what to fix - so you need to lay out a non-working option

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question