add random delay to auth flow
This commit is contained in:
parent
f257b131ff
commit
4152dfe086
1 changed files with 21 additions and 0 deletions
21
auth.go
21
auth.go
|
|
@ -14,6 +14,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -160,6 +162,12 @@ func (s *Scraper) IsLoggedIn() bool {
|
|||
return s.isLogged
|
||||
}
|
||||
|
||||
// randomDelay introduces a random delay between 1 and 3 seconds
|
||||
func randomDelay() {
|
||||
delay := time.Duration(3000+rand.Intn(5000)) * time.Millisecond
|
||||
time.Sleep(delay)
|
||||
}
|
||||
|
||||
// Login to Twitter
|
||||
// Use Login(username, password) for ordinary login
|
||||
// or Login(username, password, email) for login if you have email confirmation
|
||||
|
|
@ -182,6 +190,8 @@ func (s *Scraper) Login(credentials ...string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
randomDelay()
|
||||
|
||||
// flow start
|
||||
data := map[string]interface{}{
|
||||
"flow_name": "login",
|
||||
|
|
@ -197,6 +207,8 @@ func (s *Scraper) Login(credentials ...string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
randomDelay()
|
||||
|
||||
// flow instrumentation step
|
||||
data = map[string]interface{}{
|
||||
"flow_token": flowToken,
|
||||
|
|
@ -212,6 +224,8 @@ func (s *Scraper) Login(credentials ...string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
randomDelay()
|
||||
|
||||
// flow username step
|
||||
data = map[string]interface{}{
|
||||
"flow_token": flowToken,
|
||||
|
|
@ -235,6 +249,8 @@ func (s *Scraper) Login(credentials ...string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
randomDelay()
|
||||
|
||||
// flow password step
|
||||
data = map[string]interface{}{
|
||||
"flow_token": flowToken,
|
||||
|
|
@ -250,6 +266,8 @@ func (s *Scraper) Login(credentials ...string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
randomDelay()
|
||||
|
||||
// flow duplication check
|
||||
data = map[string]interface{}{
|
||||
"flow_token": flowToken,
|
||||
|
|
@ -273,6 +291,9 @@ func (s *Scraper) Login(credentials ...string) error {
|
|||
if confirmation == "" {
|
||||
return fmt.Errorf("confirmation data required for %v", confirmationSubtask)
|
||||
}
|
||||
|
||||
randomDelay()
|
||||
|
||||
// flow confirmation
|
||||
data = map[string]interface{}{
|
||||
"flow_token": flowToken,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue