added foryou timeilne
This commit is contained in:
parent
cf1575a1a3
commit
c9696514c4
2 changed files with 145 additions and 0 deletions
72
tweets.go
72
tweets.go
|
|
@ -396,3 +396,75 @@ func (s *Scraper) FetchHomeTweets(_ string, maxTweetsNbr int, cursor string) ([]
|
|||
tweets, nextCursor := timeline.parseTweets()
|
||||
return tweets, nextCursor, nil
|
||||
}
|
||||
|
||||
// GetForYouTweets returns channel with tweets from for you timeline
|
||||
func (s *Scraper) GetForYouTweets(ctx context.Context, maxTweetsNbr int) <-chan *TweetResult {
|
||||
return getTweetTimeline(ctx, "", maxTweetsNbr, s.FetchHomeTweets)
|
||||
}
|
||||
|
||||
// FetchForYouTweets gets tweets from for you timline, via the Twitter frontend API.
|
||||
func (s *Scraper) FetchForYouTweets(_ string, maxTweetsNbr int, cursor string) ([]*Tweet, string, error) {
|
||||
if maxTweetsNbr > 200 {
|
||||
maxTweetsNbr = 200
|
||||
}
|
||||
|
||||
req, err := s.newRequest("GET", "https://twitter.com/i/api/graphql/1u0Wlkw6Ru1NwBUD-pDiww/HomeTimeline")
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
variables := map[string]interface{}{
|
||||
"count": maxTweetsNbr,
|
||||
"includePromotedContent": true,
|
||||
"latestControlAvailable": true,
|
||||
"requestContext": "launch",
|
||||
"withCommunity": true,
|
||||
}
|
||||
|
||||
if cursor != "" {
|
||||
variables["cursor"] = cursor
|
||||
}
|
||||
|
||||
features := map[string]interface{}{
|
||||
"rweb_tipjar_consumption_enabled": true,
|
||||
"responsive_web_graphql_exclude_directive_enabled": true,
|
||||
"verified_phone_label_enabled": false,
|
||||
"creator_subscriptions_tweet_preview_api_enabled": true,
|
||||
"responsive_web_graphql_timeline_navigation_enabled": true,
|
||||
"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,
|
||||
"view_counts_everywhere_api_enabled": true,
|
||||
"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,
|
||||
"rweb_video_timestamps_enabled": true,
|
||||
"longform_notetweets_rich_text_read_enabled": true,
|
||||
"longform_notetweets_inline_media_enabled": true,
|
||||
"responsive_web_enhance_cards_enabled": false,
|
||||
}
|
||||
|
||||
req.Header.Set("content-type", "application/json")
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
tweets, nextCursor := timeline.parseTweets()
|
||||
return tweets, nextCursor, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue