From dea37c7556d0c9583e776f79beabbe8795082d3f Mon Sep 17 00:00:00 2001 From: Alessio Date: Sat, 3 Jun 2023 07:51:39 -0300 Subject: [PATCH] Fix cursor bug in authenticated sessions --- cmd/tests.sh | 2 +- scraper/api_request_utils.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/tests.sh b/cmd/tests.sh index 3442263..8942cf8 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -319,7 +319,7 @@ tw --session Offline_Twatter.session list_followed > /dev/null # Dummy operatio # Test search -tw --session Offline_Twatter -n 1 search "from:michaelmalice constitution" # TODO: remove `-n 1` once the authenticated cursor bug is fixed +tw --session Offline_Twatter search "from:michaelmalice constitution" test $(sqlite3 twitter.db "select count(*) from tweets where user_id = 44067298 and text like '%constitution%'") -gt "30" # Not sure exactly how many diff --git a/scraper/api_request_utils.go b/scraper/api_request_utils.go index 3ef4b48..afae5fa 100644 --- a/scraper/api_request_utils.go +++ b/scraper/api_request_utils.go @@ -396,7 +396,7 @@ func (api API) GetSpace(id SpaceID) (SpaceResponse, error) { return result, err } -func (api API) GetTweet(id TweetID, cursor string) (TweetResponse, error) { +func (api *API) GetTweet(id TweetID, cursor string) (TweetResponse, error) { url, err := url.Parse(fmt.Sprintf("%s%d.json", API_CONVERSATION_BASE_PATH, id)) if err != nil { panic(err) @@ -414,7 +414,7 @@ func (api API) GetTweet(id TweetID, cursor string) (TweetResponse, error) { } // Resend the request to get more replies if necessary -func (api API) GetMoreReplies(tweet_id TweetID, response *TweetResponse, max_replies int) error { +func (api *API) GetMoreReplies(tweet_id TweetID, response *TweetResponse, max_replies int) error { last_response := response for last_response.GetCursor() != "" && len(response.GlobalObjects.Tweets) < max_replies { fresh_response, err := api.GetTweet(tweet_id, last_response.GetCursor()) @@ -466,7 +466,7 @@ func (api API) GetUser(handle UserHandle) (APIUser, error) { return result.ConvertToAPIUser(), err } -func (api API) Search(query string, cursor string) (TweetResponse, error) { +func (api *API) Search(query string, cursor string) (TweetResponse, error) { url, err := url.Parse("https://twitter.com/i/api/2/search/adaptive.json") if err != nil { panic(err) @@ -487,7 +487,7 @@ func (api API) Search(query string, cursor string) (TweetResponse, error) { return result, err } -func (api API) GetMoreTweetsFromSearch(query string, response *TweetResponse, max_results int) error { +func (api *API) GetMoreTweetsFromSearch(query string, response *TweetResponse, max_results int) error { last_response := response for last_response.GetCursor() != "" && len(response.GlobalObjects.Tweets) < max_results { fresh_response, err := api.Search(query, last_response.GetCursor())