tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
6.75k stars 1.37k forks source link

Account getting banned after successful login using phone code or qr code #2920

Open Charlygnusa opened 1 month ago

Charlygnusa commented 1 month ago

Hi, I've been experiencing issues with my Telegram account getting banned after successful logins using phone code or QR code.

I'm using TDLib's tdjson in Python, following the example from tdjson_example.py. When I log in using setAuthenticationPhoneNumber and then enter the code with setAuthenticationCode, it works initially. However, a few moments later, my Telegram account gets logged out from all devices. When I try to log in directly from the Telegram mobile app, I get an "EMAIL_NOT_ALLOWED" error, indicating that my account might be banned.

The next day, I'm able to log in again from mobile. I tried using TDLib with requestQrCodeAuthentication for QR code login, but the same issue occurred: I can log in for a short time, then I get automatically logged out from all devices.

This my code:

Screenshot from 2024-06-07 17-08-07

What should I do? Is there something wrong with my implementation?

Thanks

levlam commented 1 month ago

"EMAIL_NOT_ALLOWED" isn't related in any way to account ban. The error means that you must use another email address to set up as log in email.

levlam commented 1 month ago

If the server detects automatic user registration or any other suspicious activity, it can ban the accounts involved. If you think that an account was banned by a mistake, please try to log in to the account from an official mobile app and send an email to recover the account by following instructions provided by the app.

Charlygnusa commented 1 month ago

I tried using my second email to log in from the official mobile app and it worked. Then I tried again using TDLib as I mentioned before. My account logged in successfully, but a few moments later it automatically logged out from all devices. Then I tried to log in again using the official mobile app with my second email, but it couldn't log in, and I got the same error as with my first email: EMAIL_NOT_ALLOWED.

Just now, I tried using my first email, and I was able to log in through the official mobile app. Then when I tried to log in using tdlib, the same problem happened again, and now I can't log in with either my first or second email.

It seems that my account can't log in for a while (maybe a few hours) after a successful login via tdlib. I tried using another account, and it had the same problem. Basically, my account gets automatically logged out from all devices when I successfully log in using tdlib, and I can't log in again. Why is this happening?

The last event log is:

{'@type': 'updateHavePendingNotifications', 'have_delayed_notifications': False, 'have_unreceived_notifications': True, '@client_id': 1}
{'@type': 'updateAuthorizationState', 'authorization_state': {'@type': 'authorizationStateLoggingOut'}, '@client_id': 1}
{'@type': 'updateConnectionState', 'state': {'@type': 'connectionStateConnecting'}, '@client_id': 1}
{'@type': 'updateHavePendingNotifications', 'have_delayed_notifications': False, 'have_unreceived_notifications': False, '@client_id': 1}
{'@type': 'updateAuthorizationState', 'authorization_state': {'@type': 'authorizationStateClosed'}, '@client_id': 1}
levlam commented 1 month ago

The log lines just states that the account was logged out.

Charlygnusa commented 1 month ago

Yes, thats why I dont know where the error is, because there is no error in the log. My account just suddenly logged out a short time after I successfully logged in, and it logged out from all my devices.

grmozhaev commented 2 weeks ago

Hello! Having the same issue with logging out, came to check out your story. Did you have any luck tackling this problem? After a couple of logouts I also had to enter my email and got an 'EMAIL_NOT_ALLOWED' error. I used another library, Telethon, but the result is the same as yours. Would be glad to hear you found a solution. DId you?

wanlongstone commented 1 week ago

Yes, thats why I dont know where the error is, because there is no error in the log. My account just suddenly logged out a short time after I successfully logged in, and it logged out from all my devices.

Is this problem solved? I have the same problem.

grmozhaev commented 1 week ago

@wanlongstone Hi, the problem was (at least in my case) that every time I ran the script it created a new session. Keep a persistent session and you'll be just fine. When you set up your script with Telethon, ensure you are using a session file. This file helps maintain your session across multiple runs without needing to reauthenticate each time. Here is how you might initialize Telethon with a session file:

from telethon import TelegramClient

api_id = 'YOUR_API_ID' api_hash = 'YOUR_API_HASH' phone = 'YOUR_PHONE_NUMBER'

// The 'anon' here refers to the session file name that will be created and reused. client = TelegramClient('anon', api_id, api_hash)

Hope it helps!

P.S. And about that email error: it goes away by itself in like a day but reinstalling an app on your smartphone also worked for me. Just in case