vk公司_api.exceptions.ApiError错误:[15]拒绝访问:无法调用此方法

2024-04-24 12:26:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着做VK机器人,有代码

import vk_api
import requests

session = requests.Session()
login, password = 'my login', 'my passwd'
vk_session = vk_api.VkApi(login, password)
try:
    vk_session.auth(token_only=True)
except vk_api.AuthError as error_msg:
    print(error_msg)

from vk_api.longpoll import VkLongPoll, VkEventType
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.text == '1st variant of phrase' or event.text == '2nd variant of phrase':
            if event.from_user: 
                vk.messages.send( 
                    user_id=event.user_id,
                    message='Ваш текст'
        )
            elif event.from_chat: 
                vk.messages.send( 
                    chat_id=event.chat_id,
                    message='text'
        )
                break
        continue

但我有个错误

  File "C:\Users\тандер\Desktop\bot.py", line 14, in <module>
    longpoll = VkLongPoll(vk_session)
  File "D:\Programs\Python\Python38\lib\site-packages\vk_api\longpoll.py", line 517, in __init__
    self.update_longpoll_server()
  File "D:\Programs\Python\Python38\lib\site-packages\vk_api\longpoll.py", line 531, in update_longpoll_server
    response = self.vk.method('messages.getLongPollServer', values)
  File "D:\Programs\Python\Python38\lib\site-packages\vk_api\vk_api.py", line 646, in method
    raise error
vk_api.exceptions.ApiError: [15] Access denied: no access to call this method

我应该怎么做来纠正这个错误?我尝试将我的VK令牌输入到VKèu会话中,但它不起作用 帮助请<;3


Tags: textinpyimporteventapiidsession