P
P
Pavel Dyukarev2017-06-17 00:12:37
Python
Pavel Dyukarev, 2017-06-17 00:12:37

The vkapi.messages.getHistory method doesn't work, what's wrong?

Hello!
I set myself the following task: download the history of correspondence from a VK group conversation.
I am using Python 3.4.4 + vk library

import vk
from MyVkData import MyVkData

# использую созданный мною класс MyVkData чтобы скрыть свои пароли логины
session = vk.AuthSession(app_id=MyVkData.APP_ID, user_login=MyVkData.LOGIN,
                         user_password=MyVkData.GET_PASSWORD(),
                         access_token=MyVkData.TOKEN, scope='messages, offline' )
vkapi = vk.API(session)

# беседа в вк называется  '1+сердечко'
chat = vkapi.messages.searchDialogs(q='1')
chat = chat[0]

# получаю chat_id = 1
chat_id = chat['chat_id']


history = vkapi.messages.getHistory(count=200, peer_id=2000000000 + chat_id)
print(history)

As a result, the code returns an error: vk.exceptions.VkAPIError: 100. One of the parameters specified was missing or invalid: user_id is undefined. request_params = {'oauth': '1', 'count': '200', 'method': 'messages.getHistory', 'peer_id': '2000000001'
} a person and not a conversation, then the code will work with a bang. Returns a JSON file with the conversation history of the dialog.
For the past hour I have been racking my brains reading the documentation , studying the messages.getHistory method and I just can’t understand why it doesn’t work if the peer_id parameter is used.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petr Flaks, 2017-06-17
@PavelDuk

You forget to pass the API version in your requests, because VK considers that you are working with the third version of the API (the current one is 5.65). Accordingly, the parameters for requests in different versions of the API may vary.
The documentation for the library you are using has an example of specifying the API version :

session = vk.Session()
api = vk.API(session, v='5.35', lang='ru', timeout=10)
api.method.name(param=value)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question