add auth with token
This commit is contained in:
parent
d45ac95957
commit
8d81775809
1 changed files with 37 additions and 0 deletions
37
auth.go
37
auth.go
|
|
@ -401,6 +401,43 @@ func (s *Scraper) SetCookies(cookies []*http.Cookie) {
|
||||||
s.client.Jar.SetCookies(twURL, cookies)
|
s.client.Jar.SetCookies(twURL, cookies)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Scraper) SetAuthToken(authToken string, ct0 string) {
|
||||||
|
var (
|
||||||
|
cookies []*http.Cookie
|
||||||
|
expires = time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
)
|
||||||
|
|
||||||
|
cookies = append(cookies, &http.Cookie{
|
||||||
|
Name: "auth_token",
|
||||||
|
Value: authToken,
|
||||||
|
Path: "",
|
||||||
|
Domain: "twitter.com",
|
||||||
|
Expires: expires,
|
||||||
|
RawExpires: "",
|
||||||
|
MaxAge: 0,
|
||||||
|
Secure: false,
|
||||||
|
HttpOnly: false,
|
||||||
|
SameSite: 0,
|
||||||
|
Raw: "",
|
||||||
|
})
|
||||||
|
|
||||||
|
cookies = append(cookies, &http.Cookie{
|
||||||
|
Name: "ct0",
|
||||||
|
Value: ct0,
|
||||||
|
Path: "",
|
||||||
|
Domain: "twitter.com",
|
||||||
|
Expires: expires,
|
||||||
|
RawExpires: "",
|
||||||
|
MaxAge: 0,
|
||||||
|
Secure: false,
|
||||||
|
HttpOnly: false,
|
||||||
|
SameSite: 0,
|
||||||
|
Raw: "",
|
||||||
|
})
|
||||||
|
|
||||||
|
s.SetCookies(cookies)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Scraper) ClearCookies() {
|
func (s *Scraper) ClearCookies() {
|
||||||
s.client.Jar, _ = cookiejar.New(nil)
|
s.client.Jar, _ = cookiejar.New(nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue