telegram-s / telegram-api-old

Telegram Api library for java
MIT License
138 stars 64 forks source link

save auth to avoid users to enter the code from a text message #32

Open winagain opened 9 years ago

winagain commented 9 years ago

hello , everyone , is there anyone able to save the auth to a file successfully ?

Method 01 : save the whole apiState (source : https://github.com/ex3ndr/telegram-api/issues/22) result : not success

Method 02 : using AuthExportAuthorization (source : https://core.telegram.org/api/datacenter , Authorization Transfer) result : not success TLExportedAuthorization authExported = api.doRpcCall(new TLRequestAuthExportAuthorization(destDC)) ;

TLBytes authBytes = authExported.getByte() ; // ==> can't be java.io.NotSerializ

bytes[] authBytes = authExported.getByte().getDate() ; // ==> AUTH_BYTES_INVALID using it in AuthImportAuthorization

voleon commented 9 years ago

I have success with Method01. I used implementation of AbsApiState from telegram-bot (https://github.com/ex3ndr/telegram-bot/blob/master/app/src/main/java/org/telegram/bot/engine/MemoryApiState.java). I've added interface Serializable to MemoryApiState class and inner class ConnectionInfo. And then just serialize apiState to file on auth, and deserialize from file when application starts.

winagain commented 9 years ago

voleon , thank you very much , i do it successfully. Your comment give me some light to continue in Method 1 and the missing part is need to re-connect by :

    connections.put(1, new ConnectionInfo[]{
            new ConnectionInfo(1, 0, isTest ? "149.154.167.xx" : "149.154.167.xx", 443)
    });     
Chaki1306 commented 7 years ago

Hello, help me. Where serialize apiState?(In which place?) Can you give an example? I have an error(SecurityException) when deserialize from file when application starts