Answer the question
In order to leave comments, you need to log in
Can you help me fix the error in the longpoll code?
When I run the code below I get the error
vk_api.exceptions.ApiError: [15] Access denied: no access to call this method
And sometimes
vk api.exceptions.apierror 5 user authorization failed no access token passed
I wanted to on all messages that came to me in PM had a definite answer. Can you send me the corrected code. I don't understand what is wrong. Thanks in advance!!!
import vk_api
import requests
from vk_api.longpoll import VkLongPoll, VkEventType
session = requests.Session()
token = 'мой токен, полученный на сайте https://vkhost.github.io/ (выбрал katemobile)'
vk_session = vk_api.VkApi(token)
try:
vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
print(error_msg)
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
if event.from_user:
vk.messages.send(user_id=event.user_id,message='Ваш текст')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question