AUTH_KEY_UNREGISTERED when using custom sessionUserId
Hi, guys! @sochix @marshallmick007 @ahmadalli @ra0o0f @Starli0n
What I do:
- Create client TelegramClient client = new TelegramClient(Api_Id, Api_Hash, sessionUserId: guid); bool connectionResult = await client.ConnectAsync(); string hash = await client.SendCodeRequestAsync(phone); TLUser user = await client.MakeAuthAsync(phone, hash, code);
It's ok on this step
- Then I close app and run again.
- TelegramClient client = new TelegramClient(Api_Id, Api_Hash, sessionUserId: guid); bool connectionResult = await client.ConnectAsync(); var dialogs = await client.GetUserDialogsAsync();
and now I have message 'AUTH_KEY_UNREGISTERED'
but if not using custom sessionUserId and creating and using by default new TelegramClient(Api_Id, Api_Hash) - it's all ok and no one error messages
@messire try use TelegramClient insted of TLUser. Consider that sessionUserId is path to dat file with session.
@AskoldMakaruk for example?
@messire
You can save dat files in current directory like this:
string fullPathToDat = Directory.GetCurrentDirectory()+"\\filename.dat"
Create .dat:
TelegramClient client = new TelegramClient(Api_Id, Api_Hash, new FileSessionStore(), fullPathToDat);
await client.ConnectAsync();
string hash = await client.SendCodeRequestAsync(phone);
await client.MakeAuthAsync(phone, hash, code);
Load .dat
var store = new FileSessionStore();
TelegramClient client = new TelegramClient(Api_Id, Hash, store, fullPathToDat);
await client.ConnectAsync();
Hi I created and connected (ConnectAsync), sent the code and authed (MakeAuthAsync) this function successfully returned the TLUser object, also IsUserAuthorized returns true. At this time everything is ok and GetUserDialogsAsync is ok
Now if I close the program and start it again, despite IsUserAuthorized return true, but SendMessageAsync throws a AUTH_KEY_UNREGISTERED
The 'AUTH_KEY_UNREGISTERED' error is on :
var dialogs = (TLDialogs)await _client.GetUserDialogsAsync();
full code
var store = new FileSessionStore();
TelegramClient _client = new TelegramClient(11***9, "b****445dff9d19ff3631", store, "sessionName");
await _client.ConnectAsync();
if (!_client.IsUserAuthorized())
{
var hashKey = await _client.SendCodeRequestAsync("+********");
TLUser myuser = await _client.MakeAuthAsync("+********", hashKey, TelegramSendedCode);
}
var dialogs = (TLDialogs)await _client.GetUserDialogsAsync();
I already test:
client.ConnectAsync()
client.IsUserAuthorized()
both TRUE
please help me tanks
+1. The same problem.
Some one solved this problem?
Maybe ConnectAsync(reconnect = true) ?!
Hi! If you already have file session.dat, this works fo me: string fullPathToDat = Directory.GetCurrentDirectory() + "\session"; var store = new FileSessionStore(); client = new TelegramClient(apiId, apiHash, store, fullPathToDat); await client.ConnectAsync(false);
Проблему решил используя client.ConnectAsync(false); Не знаю точно в чём проблема, но как мне кажется вопрос в методе обращения к серверу, в режиме Reconnect = true, каждое новое обращение к client меняет AuthKey и нужно после каждого обращения делать пересохранение сессии.