From a27f12a91510b2c547e731b42fdf8d00ee2078bb Mon Sep 17 00:00:00 2001 From: Alessio Date: Tue, 6 Jun 2023 22:48:42 -0300 Subject: [PATCH] Add UserID to the API session --- scraper/api_request_utils.go | 6 ++++++ scraper/authentication_test.go | 1 + 2 files changed, 7 insertions(+) diff --git a/scraper/api_request_utils.go b/scraper/api_request_utils.go index 5aac198..3e2ce19 100644 --- a/scraper/api_request_utils.go +++ b/scraper/api_request_utils.go @@ -18,6 +18,7 @@ const API_USER_TIMELINE_BASE_PATH = "https://api.twitter.com/2/timeline/profile/ type API struct { UserHandle UserHandle + UserID UserID IsAuthenticated bool GuestToken string Client http.Client @@ -38,6 +39,7 @@ func InitApi(newApi API) { type api_outstruct struct { Cookies []*http.Cookie + UserID UserID UserHandle UserHandle IsAuthenticated bool GuestToken string @@ -49,6 +51,7 @@ var TWITTER_BASE_URL = url.URL{Scheme: "https", Host: "twitter.com"} func (api API) MarshalJSON() ([]byte, error) { result, err := json.Marshal(api_outstruct{ Cookies: api.Client.Jar.Cookies(&TWITTER_BASE_URL), + UserID: api.UserID, UserHandle: api.UserHandle, IsAuthenticated: api.IsAuthenticated, GuestToken: api.GuestToken, @@ -73,6 +76,7 @@ func (api *API) UnmarshalJSON(data []byte) error { cookie_jar.SetCookies(&TWITTER_BASE_URL, in_struct.Cookies) api.IsAuthenticated = in_struct.IsAuthenticated api.GuestToken = in_struct.GuestToken + api.UserID = in_struct.UserID api.UserHandle = in_struct.UserHandle api.Client = http.Client{ @@ -170,6 +174,7 @@ func (api *API) LogIn(username string, password string) { Subtasks []struct { OpenAccount struct { User struct { + ID int Name string ScreenName string `json:"screen_name"` } @@ -186,6 +191,7 @@ func (api *API) LogIn(username string, password string) { panic(err) } + api.UserID = UserID(final_result.Subtasks[0].OpenAccount.User.ID) api.UserHandle = UserHandle(final_result.Subtasks[0].OpenAccount.User.ScreenName) api.update_csrf_token() diff --git a/scraper/authentication_test.go b/scraper/authentication_test.go index 49f52a8..977b3d4 100644 --- a/scraper/authentication_test.go +++ b/scraper/authentication_test.go @@ -27,6 +27,7 @@ func TestJsonifyApi(t *testing.T) { {Name: "name2", Value: "name2", HttpOnly: true}, }) api := API{ + UserID: UserID(1423), UserHandle: UserHandle("userhandle"), IsAuthenticated: true, GuestToken: "guest token",