From 3e06de08b556f8fcdacfc30c706e0ab25370bc6c Mon Sep 17 00:00:00 2001 From: Valentine Date: Tue, 9 Jul 2024 04:48:31 +0300 Subject: [PATCH] fixed FetchHomeTweets --- tweets.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tweets.go b/tweets.go index a122c47..35b3152 100644 --- a/tweets.go +++ b/tweets.go @@ -1,11 +1,8 @@ package twitterscraper import ( - "bytes" "context" - "encoding/json" "fmt" - "io" "net/url" "strconv" ) @@ -336,7 +333,7 @@ func (s *Scraper) FetchHomeTweets(_ string, maxTweetsNbr int, cursor string) ([] maxTweetsNbr = 200 } - req, err := s.newRequest("POST", "https://twitter.com/i/api/graphql/MquF6747JmE_NQYdkIH0OQ/HomeLatestTimeline") + req, err := s.newRequest("GET", "https://twitter.com/i/api/graphql/9EwYy8pLBOSFlEoSP2STiQ/HomeLatestTimeline") if err != nil { return nil, "", err } @@ -348,7 +345,7 @@ func (s *Scraper) FetchHomeTweets(_ string, maxTweetsNbr int, cursor string) ([] "requestContext": "launch", } features := map[string]interface{}{ - "rweb_tipjar_consumption_enabled": false, + "rweb_tipjar_consumption_enabled": true, "responsive_web_graphql_exclude_directive_enabled": true, "verified_phone_label_enabled": false, "creator_subscriptions_tweet_preview_api_enabled": true, @@ -356,6 +353,7 @@ func (s *Scraper) FetchHomeTweets(_ string, maxTweetsNbr int, cursor string) ([] "responsive_web_graphql_skip_user_profile_image_extensions_enabled": false, "communities_web_enable_tweet_community_results_fetch": true, "c9s_tweet_anatomy_moderator_badge_enabled": true, + "articles_preview_enabled": true, "tweetypie_unmention_optimization_enabled": true, "responsive_web_edit_tweet_api_enabled": true, "graphql_is_translatable_rweb_tweet_is_translatable_enabled": true, @@ -363,6 +361,7 @@ func (s *Scraper) FetchHomeTweets(_ string, maxTweetsNbr int, cursor string) ([] "longform_notetweets_consumption_enabled": true, "responsive_web_twitter_article_tweet_consumption_enabled": true, "tweet_awards_web_tipping_enabled": false, + "creator_subscriptions_quote_tweet_preview_enabled": false, "freedom_of_speech_not_reach_fetch_enabled": true, "standardized_nudges_misinfo": true, "tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled": true, @@ -373,14 +372,11 @@ func (s *Scraper) FetchHomeTweets(_ string, maxTweetsNbr int, cursor string) ([] } req.Header.Set("content-type", "application/json") - body := map[string]interface{}{ - "variables": variables, - "features": features, - "queryId": "CTOVqej0JBXAZSwkp1US0g", - } - b, _ := json.Marshal(body) - req.Body = io.NopCloser(bytes.NewReader(b)) + query := url.Values{} + query.Set("variables", mapToJSONString(variables)) + query.Set("features", mapToJSONString(features)) + req.URL.RawQuery = query.Encode() var timeline homeTimeline err = s.RequestAPI(req, &timeline)