steavy29 / Telegram.Net

Telegram (http://telegram.org) client library implemented in C#.
17 stars 6 forks source link

client.SendCode(...) error #27

Closed JackieMond closed 7 years ago

JackieMond commented 7 years ago

Help please, I'm trying to use Telegram.NET, I've created developer account at telegram website and got my Api ID and Api Hash so far so good.

i'm able to perform client.Start() and it returns me "connected"

after that I got to client.SendCode() and it returns me an exception which says API_ID_INVALID. i know how to copy and paste so i am pretty sure its not a number mistake..

it worked once on my friend computer when i used it without DeviceInfo so ill be glad if someone can send me an example of : DeviceInfo(string deviceModel, string systemVersion, string appVersion, string langCode)

another option is the server, in my app configuration page on telegram i get 2 servers which are different than your default server: TEST SERVER : 149.154.167.40:443 PROD SERVER: 149.154.167.50:443

tried them both but it still returns me API_ID_INVALID any suggestions ?

JackieMond commented 7 years ago

System.AggregateException was unhandled HResult=-2146233088 Message=One or more errors occurred. Source=mscorlib StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at Telegram.NET.Program.Program.Main(String[] args) in \Telegram.NET.Program\Program.cs:line 24 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: HResult=-2146233088 Message=BadRequest - API_ID_INVALID Source=Telegram.Net.Core errorMessage=API_ID_INVALID StackTrace: at Telegram.Net.Core.Requests.MtProtoRequest.ThrowIfHasError() in \Telegram.Net-master\Telegram.Net.Core\Requests\MtProtoRequest.cs:line 62 at Telegram.Net.Core.TelegramClient.d35.MoveNext() in \Telegram.Net-master\Telegram.Net.Core\TelegramClient.cs:line 320 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Telegram.NET.Program.Program.d4.MoveNext() in \Telegram.Net-master\Telegram.NET.Program\Program.cs:line 36 InnerException:

steavy29 commented 7 years ago

Hi, Jackie. Could you please show your code how you create/initialize and use TelegramClient?

JackieMond commented 7 years ago

public static void Main(string[] args) { TelegramConnect().Wait(); }

    private static async Task<TelegramClient> CreateClient()
    {
        FileSessionStore sessionStore = new FileSessionStore();
        client = new TelegramClient(sessionStore, apiId, apiHash, new DeviceInfo("Telegram Test", "Telegram Test", "Telegram Test", "en"));
        clientConnected = await client.Start();

        return client;
    }

    private static async Task<TelegramClient> TelegramConnect()
    {   
        client = await CreateClient();

        if (!client.IsUserAuthorized())
        {
            var codeRequest = await client.SendCode(numberToRegister, VerificationCodeDeliveryType.NumericCodeViaSms);
            var hash = codeRequest.phoneCodeHash;

            var code = ""; // you can change code in debugger

            await client.SignIn(numberToRegister, hash, code);
        }

        connected = client.IsUserAuthorized() ? true : false;

        return client;
    }
claytonbnu commented 7 years ago

I have same problem :(

steavy29 commented 7 years ago

Hi. I'll check this today in the evening. Sorry for the delay.

steavy29 commented 7 years ago

Ok, so: 1) About server ip addresses: you don't have to specify it. The library only needs an initial server ip address(which is currently hard-coded) and then it will automatically make an internal redirect to the correct server. So you don't need to specify your address anywhere. 2) You can have a look how DeviceInfo is used somewhere in Tests. Here is an example: new DeviceInfo("Telegram Test", "Telegram Test", "Telegram Test", "en") 3) About your error: BadRequest - API_ID_INVALID This error is generated by Telegram server so it is very likely that your API ID is invalid indeed. I've checked your code with my own API ID and it worked well. If it's appropriate, you could share it with me and I'll test it(ofc, preferably somewhere in private messages).

HemmatSharp commented 7 years ago

I have same problem :(

steavy29 commented 7 years ago

In my Api configuration I also have the very same servers: TEST SERVER : 149.154.167.40:443 PROD SERVER: 149.154.167.50:443

With Test server(149.154.167.40:443) I get the same error as you do: API_ID_INVALID which is probably ok. But with Prod Server(149.154.167.50:443) it works just fine for me. By default TelegramClient uses 149.154.167.51 server which is one of telegram prod servers.

steavy29 commented 7 years ago

Did you try to specify your server address explicitly through constructor parameter in TelegramClient? (You should specify only server address without port. F.e. 149.154.167.50)

JackieMond commented 7 years ago

https://github.com/LonamiWebs/Telethon/issues/46

https://github.com/sochix/TLSharp/issues/442

http://stackoverflow.com/questions/39299920/work-with-telegram-api-api-id-invalid

steavy29 commented 7 years ago

Hi, Jackie. Is it possible for you to share your apiId/hash/ips with me so that I could try to reproduce it? In private, ofc.

samuelg78 commented 7 years ago

This error can be replicated by using new mobile numbers. Newly registered number will have a 6-digit api_id which constitutes to this error.

steavy29 commented 7 years ago

Ok, I'll try to register new Api and check it. Thanks for the info.

JackieMond commented 7 years ago

no need.. its working again.. telegram problem and they fixed it, they could not support 6 digit api_id thx for the help guys

JackieMond commented 7 years ago

issue solved.. you can close now 💯

samuelg78 commented 7 years ago

Great to hear that.

steavy29 commented 7 years ago

Cool. Thanks for posting in this thread.