A
A
Andriy12182015-07-18 00:16:47
JavaScript
Andriy1218, 2015-07-18 00:16:47

The messages.getHistory VK API method does not work. How to get full message history?

I want to get the message history using the messages.getHistory method from the VK API.

WebRequest request = WebRequest.Create("https://api.vk.com/method/messages.getHistory?user_id=" + id + "&offset=" + m + "&count=200&access_token=" + token);
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
response.Close();
       
responseFromServer = HttpUtility.HtmlDecode(responseFromServer);//возвращает "{\"response\":[0]}"
JToken token = JToken.Parse(responseFromServer);
messagesList = token["response"].Children().Skip(1).Select(c => c.ToObject<Friend>()).ToList();

But the response from the server is always empty: "{\"response\":[0]}"
I tried the messages.get method and it works. But I need the full message history.
Does anyone know what could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igor Serikov, 2018-12-12
@MrLeonardos

That's it, I figured it out
client.on('message', msg => {//Responds to the player
if(msg.content.startsWith("Issue")) {
if(msg.member.permissions.has('MANAGE_ROLES')){
let role = msg.guild.roles.find(c => c.name === msg.content.split(" ")[1])
let user = msg.mentions.members.first();
user.addRole( role.id);
msg.reply(`The user has been given a role!` );
console.log(`The user has been given a role `)
} else {
msg.reply(`You are not allowed to issue roles!`);
console.log (`The user is not allowed to issue roles!`);
}
}
});

E
EvgeniBlack, 2019-01-09
@EvgeniBlack

D:\Zhenya\DISCORD BOT\index.js:186
user.addRole(role.id);
^
TypeError: Cannot read property 'id' of null
at Client.client.on.msg (D:\Zhenya\DISCORD BOT\index.js:186:29)
at Client.emit (events.js:187:15)
at MessageCreateHandler.handle (D:\Zhenya\DISCORD BOT\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (D:\Zhenya\DISCORD BOT\node_modules \discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (D:\Jenya\DISCORD BOT\node_modules\discord.js\src\client\websocket\WebSocketConnection.js: 333:35)
at WebSocketConnection.onMessage (D:\Zhenya\DISCORD BOT\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (D:\Zhenya\DISCORD BOT\node_modules\ws\ lib\event-target.js:120:16)
at WebSocket.emit (events.js:182:13)
at Receiver._receiver.onmessage (D:\Zhenya\DISCORD BOT\node_modules\ws\lib\websocket.js: 137:47)
at Receiver.dataMessage (D:\Zhenya\DISCORD BOT\node_modules\ws\lib\receiver.js:409:14)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question