td icon indicating copy to clipboard operation
td copied to clipboard

SignIn fail

Open vicabert091 opened this issue 1 year ago • 2 comments

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 avatar Oct 14 '24 07:10 vicabert091

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.

prdsrm avatar Oct 15 '24 18:10 prdsrm

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

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

itbeard avatar Oct 26 '24 12:10 itbeard