Answer the question
In order to leave comments, you need to log in
VK API. getLongPollServer and getLongPollHistory. Why doesn't it catch all events?
VK API. getLongPollServer and getLongPollHistory. Why doesn't it catch all events? It does not work every time, I tried to display new_pts, sometimes some values are missing. It also doesn't work in conversations. Code below. What's wrong?
static void Main(string[] args)
{
connectToLongPool();
while (true)
{
scanMessages();
Thread.Sleep(500);
}
public static string ts;
public static string pts;
public static string new_pts = "1";
private static void connectToLongPool()
{
HttpWebRequest pollReq = (HttpWebRequest)WebRequest.Create("https://api.vk.com/method/messages.getLongPollServer?access_token=токен_от_группы&need_pts=" + new_pts + "&v=5.92");
pollReq.Method = "GET";
pollReq.Accept = "application/json";
HttpWebResponse pollResp = (HttpWebResponse)pollReq.GetResponse();
StreamReader reader = new StreamReader(pollResp.GetResponseStream());
StringBuilder builder = new StringBuilder();
string pollData = builder.Append(reader.ReadToEnd()).ToString();
JObject poolConnectJson = JObject.Parse(pollData);
ts = poolConnectJson["response"]["ts"].ToString();
pts = poolConnectJson["response"]["pts"].ToString();
}
private static void scanMessages()
{
HttpWebRequest poolMessages = (HttpWebRequest)WebRequest.Create("https://api.vk.com/method/messages.getLongPollHistory?group_id=190776459&ts=" + ts + "&access_token=" + "токен_группы&v=5.92" + "&pts=" + pts + "&lp_version=3&msgs_limit=10000&events_limit=10000");
poolMessages.Method = "GET";
poolMessages.Accept = "application/json";
HttpWebResponse poolResponse = (HttpWebResponse)poolMessages.GetResponse();
StreamReader reader = new StreamReader(poolResponse.GetResponseStream());
StringBuilder builder = new StringBuilder();
string textResp = builder.Append(reader.ReadToEnd()).ToString();
JObject poolConnectJson = JObject.Parse(textResp);
Console.WriteLine(textResp);
//MsgPrint(poolConnectJson);
new_pts = poolConnectJson["response"]["new_pts"].ToString();
Console.WriteLine(new_pts);
}
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