sochix / TLSharp

Telegram client library implemented in C#
1.01k stars 380 forks source link

Flood prevention! #992

Closed Vxer-Lee closed 3 years ago

Vxer-Lee commented 3 years ago

When I get the image ID from the chat record and download it, the server returns this message. What should I do?

Flood prevention. Telegram now requires your program to do requests again only after 5 seconds have passed (TimeToWait property). If you think the culprit of this problem may lie in TLSharp's implementation, open a Github issue please.

image

LocalId:6781 Secret:3101091358733321214 VolumeId:500041600961 Size:56140

Code:


public virtual async Task Telegram_Download_Photo(string name,int LocalId,long Secret,long VolumeId)
{
    var client = NewClient();
    await client.ConnectAsync();
    BinaryWriter bw;
    bw = new BinaryWriter(new FileStream(name, FileMode.Create));
    try
    {
        TLAbsInputFileLocation TLAbsInputFileLocation = new TLInputFileLocation()
        {
            LocalId = LocalId,
            Secret = Secret,
            VolumeId = VolumeId
        };
        TLInputFileLocation TLInputFileLocation = TLAbsInputFileLocation as TLInputFileLocation;
       var buffer = await client.GetFile(TLInputFileLocation, 1024*512);
        bw.Write(buffer.Bytes);
        bw.Close();
    }
    catch (Exception ee)
    {
        bw.Close();
        throw ee;
    }
}
knocte commented 3 years ago

Why do you think this is a bug in TLSharp?

hosseinGanjyar commented 3 years ago

You should set Timeout for call API. If you call it continuously without a gap time, you may block from Telegram for many times.

Vxer-Lee commented 3 years ago

You should set Timeout for call API. If you call it continuously without a gap time, you may block from Telegram for many times.

Thanks !

ctphu commented 3 years ago

You should set Timeout for call API. If you call it continuously without a gap time, you may block from Telegram for many times.

Can you add example code ?

rocket-builder commented 3 years ago

You should set Timeout for call API. If you call it continuously without a gap time, you may block from Telegram for many times.

Can you add example code ?

I need code example too!