add auth with token

This commit is contained in:
Valentine 2024-02-20 17:26:54 +03:00
parent d45ac95957
commit 8d81775809

37
auth.go
View file

@ -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)
} }