Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.SendCode(...) error #27

Closed
JackieMond opened this issue Apr 6, 2017 · 17 comments
Closed

client.SendCode(...) error #27

JackieMond opened this issue Apr 6, 2017 · 17 comments

Comments

@JackieMond
Copy link

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
Copy link
Author

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.d__35.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.d__4.MoveNext() in \Telegram.Net-master\Telegram.NET.Program\Program.cs:line 36
InnerException:

@steavy29
Copy link
Owner

steavy29 commented Apr 6, 2017

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

@JackieMond
Copy link
Author

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
Copy link

I have same problem :(

@steavy29
Copy link
Owner

steavy29 commented Apr 7, 2017

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

@steavy29
Copy link
Owner

steavy29 commented Apr 9, 2017

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
Copy link

I have same problem :(

@steavy29
Copy link
Owner

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
Copy link
Owner

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)

@steavy29
Copy link
Owner

steavy29 commented Apr 13, 2017

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
Copy link

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
Copy link
Owner

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

@JackieMond
Copy link
Author

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
Copy link
Author

issue solved.. you can close now 💯

@samuelg78
Copy link

Great to hear that.

@steavy29
Copy link
Owner

Cool. Thanks for posting in this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants