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

Support Challenge verification #3

Closed
p4rkrs opened this issue Nov 1, 2019 · 13 comments
Closed

Support Challenge verification #3

p4rkrs opened this issue Nov 1, 2019 · 13 comments

Comments

@p4rkrs
Copy link

p4rkrs commented Nov 1, 2019

Hi,

It would be great to support Challenge Verification like on goinsta, ahmdrz/goinsta#198.

Thanks!

@aliforever
Copy link
Owner

Hi,

Have you tried functions in challenge.go

@p4rkrs
Copy link
Author

p4rkrs commented Nov 1, 2019

No sorry, I didn't saw.

Could give an example please? Thanks!

@aliforever
Copy link
Owner

aliforever commented Nov 1, 2019

Try this:

username, password := "", ""
err = i.Login(username, password, false)
if err != nil {
	switch err.(type) {
	case errs.CheckpointRequired:
		checkPointErr := err.(errs.CheckpointRequired)
		address  := checkPointErr.GetCheckpointUrl()
		cs := gista_helpers.NewChallengeSolver()
		ch, err := cs.GetChallengeByUrl(address)
		if err != nil {
			fmt.Println(err)
			return
		}
		chr, err := cs.GetSolveChallengeByEmail(address, ch.Config.CsrfToken, ch.RollOutHash)
		if err != nil {
			fmt.Println(err)
			return
		}
		reader := bufio.NewReader(os.Stdin)
		fmt.Println((*chr.ExtraData.Content)[1].Text)
		text, _ := reader.ReadString('\n') // Read verification code from terminal
		chsr, err := cs.SolveChallenge(address, ch.Config.CsrfToken, ch.RollOutHash, text)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(chsr)
	return
}

@p4rkrs
Copy link
Author

p4rkrs commented Nov 1, 2019

For Challenge, this is correct?

case errs.ChallengeRequired:
			checkPointErr := err.(errs.ChallengeRequired)
			address := checkPointErr.GetChallenge()
			cs := gista_helpers.NewChallengeSolver()
			ch, err := cs.GetChallengeByUrl(address.Url)
			if err != nil {
				fmt.Println(err)
				return
			}
			chr, err := cs.GetSolveChallengeByEmail(address.Url, ch.Config.CsrfToken, ch.RollOutHash)
			if err != nil {
				fmt.Println(err)
				return
			}
			reader := bufio.NewReader(os.Stdin)
			fmt.Println((*chr.ExtraData.Content)[1].Text)
			text, _ := reader.ReadString('\n') // Read verification code from terminal
			chsr, err := cs.SolveChallenge(address.Url, ch.Config.CsrfToken, ch.RollOutHash, text)
			if err != nil {
				fmt.Println(err)
				return
			}
			fmt.Println(chsr)

@aliforever
Copy link
Owner

It is correct, let me know if it doesn't work.

@p4rkrs
Copy link
Author

p4rkrs commented Nov 2, 2019

Hi,

I get this: image. Do you have the solution? I didn't change anything from the snippet above, expect removing fmt.Println((*chr.ExtraData.Content)[1].Text) because it throwed a runtime error.

@aliforever
Copy link
Owner

Does it happen after authorization?
Since you have entered your code and it's said Authorized.

@p4rkrs
Copy link
Author

p4rkrs commented Nov 2, 2019

Getting authorization... And authorized is not related to Gista or Instagram.

I think that the challenge was correctly made since chsr return i.instagram.com and CHALLENGE_REDIRECTION.

But after, doing anything with the account throw a runtime error so I guess that it's not logged properly.

@p4rkrs
Copy link
Author

p4rkrs commented Nov 2, 2019

Do you have any idea whats wrong with my code?

@aliforever
Copy link
Owner

aliforever commented Nov 2, 2019

I forgot to mention, you need to re-login after the verification. Repeat the login code after SolveChallenge.

ChallengeSolver works with Instagram web api, Gista works with Instagram Private API. That's why Solver is not built-in and is considered a helper.

If you still get challenge required error, it's because the instagram account you're trying to log-in to has been logged in with a newer API. You can change these constants to newer API constants or de-activate the account and wait for at least 3 hours, and then login to account using the old constants.

IgVersion        = "85.0.0.21.100"
VersionCode      = "146536611"

@p4rkrs
Copy link
Author

p4rkrs commented Nov 2, 2019

case errs.ChallengeRequired:
			checkPointErr := err.(errs.ChallengeRequired)
			address := checkPointErr.GetChallenge()
			cs := gista_helpers.NewChallengeSolver()
			ch, err := cs.GetChallengeByUrl(address.Url)
			if err != nil {
				fmt.Println(err)
				return
			}
			chr, err := cs.GetSolveChallengeByEmail(address.Url, ch.Config.CsrfToken, ch.RollOutHash)
			if err != nil {
				fmt.Println(err)
				return
			}
			reader := bufio.NewReader(os.Stdin)
			fmt.Println((*chr.ExtraData.Content)[1].Text)
			text, _ := reader.ReadString('\n') // Read verification code from terminal
			chsr, err := cs.SolveChallenge(address.Url, ch.Config.CsrfToken, ch.RollOutHash, text)
			if err != nil {
				fmt.Println(err)
				return
			}
			fmt.Println(chsr)
                        ig.login(username, password, false)

So I need to end the catch with a login function like this? And thanks, I'll try for the other constants..

@aliforever
Copy link
Owner

Correct, also check for the errors in the second login too. Gista will only work if there are no errors, the nil pointer error you saw was because of that.

@p4rkrs
Copy link
Author

p4rkrs commented Nov 3, 2019

It worked fine! Thanks.

@p4rkrs p4rkrs closed this as completed Nov 3, 2019
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

2 participants