fixed FetchHomeTweets

This commit is contained in:
Valentine 2024-07-09 04:48:31 +03:00
parent 5e1d9316e7
commit 3e06de08b5

View file

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