Start friendship with VkNet
- Tutorial
![](https://habrastorage.org/webt/q4/uo/gn/q4uogneid7fbgmtdy6hbvigww48.png)
First you need to create an application here .
![](https://habrastorage.org/webt/4h/ss/60/4hss60x66cmg14zhptukfo6dggs.png)
And from the settings of the newly created application, take App Id.
![](https://habrastorage.org/webt/de/oy/u2/deoyu2_twfs-gliicuuuydn47rk.png)
Now you can go directly to the code.
Create a console .net core application and add the VkNet dependency .
![](https://habrastorage.org/webt/hf/7y/gq/hf7ygqrp59s-hyvmgphntws7thu.png)
Create an instance of VkApi.
VkApiapi = newVkApi();
Now you need to log in.
api.Authorize(newApiAuthParams()
{
Login = "+79*******",
Password = "***",
ApplicationId = 684***,
Settings = Settings.All
});
Get a list of the last 20 conversations
vardialogs = api.Messages.GetConversations(newGetConversationsParams());
And now we get the last 20 messages from the first dialogue.
varmessages = api.Messages.GetHistory(newMessagesGetHistoryParams()
{PeerId = dialogs.Items[0].Conversation.Peer.Id});
And, perhaps, we will print the results.
foreach (varmsginmessages.Messages)
{
Console.WriteLine(msg.Text);
}
And send a test message to the author of the first previous message.
api.Messages.Send(newMessagesSendParams()
{
// ну или подставить сюда ид из диалога
PeerId = messages.Messages.First().Id,
Message = "Test",
RandomId = new Random().Next()
});
![](https://habrastorage.org/webt/yw/s4/kj/yws4kj5p6yqt3_gclbozx5y9pau.png)
As an example:
![](https://habrastorage.org/webt/ds/pv/ju/dspvjuy0te46vdoc3zskb3qaqk8.png)
And we received such a final code.
here
VkApiapi = newVkApi();
api.Authorize(newApiAuthParams()
{
Login = "*",
Password = "*",
ApplicationId = *,
Settings = Settings.All
});
vardialogs = api.Messages.GetConversations(newGetConversationsParams());
varmessages = api.Messages.GetHistory(newMessagesGetHistoryParams()
{PeerId = dialogs.Items[0].Conversation.Peer.Id});
Console.OutputEncoding = Encoding.UTF8;
foreach (varmsginmessages.Messages)
{
Console.WriteLine(msg.Text);
}
api.Messages.Send(newMessagesSendParams()
{
PeerId = messages.Messages.First().Id,
Message = "Test",
RandomId = new Random().Next()
});
PS
Support can be found here .