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

SignIn fail #1454

Open
vicabert091 opened this issue Oct 14, 2024 · 2 comments
Open

SignIn fail #1454

vicabert091 opened this issue Oct 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@vicabert091
Copy link

func main() {
	sessionPath := "session_phone.json"
	storage := &session.FileStorage{Path: sessionPath}
	client := telegram.NewClient(appID, appHash, telegram.Options{SessionStorage: storage})

	err := client.Run(context.Background(), func(ctx context.Context) error {
		authCli := client.Auth()

		status, err := authCli.Status(ctx)
		if err != nil {
			log.Fatal(err)
		}

		if !status.Authorized {

			phoneNumber := "+"

			code, err := authCli.SendCode(ctx, phoneNumber, auth.SendCodeOptions{
				AllowAppHash: true,
			})
			if err != nil {
				return fmt.Errorf("failed to send code: %w", err)
			}
			sentCode := code.(*tg.AuthSentCode)


			var receivedCode string
			fmt.Print("Enter the code you received: ")
			fmt.Scanln(&receivedCode)
	
			_, err = authCli.SignIn(ctx, phoneNumber, sentCode.PhoneCodeHash, receivedCode)
			if err != nil {
				log.Fatal(err)
			}
			fmt.Println("Successfully logged in!")
		}



		return nil
	})

	if err != nil {
		log.Fatalf("Failed to run Telegram client: %v", err)
	}
}

image The verification code can be received, and the parameters passed are correct. PHONE_CODE_EMPTY is still reported
@vicabert091 vicabert091 added the bug Something isn't working label Oct 14, 2024
@prdsrm
Copy link

prdsrm commented Oct 15, 2024

Hi!

Its not a bug, the phone code is actually empty.

Look here:

phoneNumber := "+"
code, err := authCli.SendCode(ctx, phoneNumber, auth.SendCodeOptions{
    AllowAppHash: true,
})

You set the phoneNumber variable to "+", so yes, the phone code is missing, this is a bad request: https://core.telegram.org/api/errors#400-bad-request.

Please set your phone number to a real phone number, the one of your telegram account, for instance: phoneNumber := "+15028258670", and it will work, then you'll be able to close the issue.

@itbeard
Copy link

itbeard commented Oct 26, 2024

_, err = authCli.SignIn(ctx, phoneNumber, sentCode.PhoneCodeHash, receivedCode)

You need to swap two last arguments. First code, than codeHash
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants