add fetch tweets by userID func

This commit is contained in:
windowsdeveloperwannabe 2023-05-10 06:09:11 -07:00
parent e30b24e903
commit 76b2215e59

View file

@ -18,15 +18,20 @@ func GetTweets(ctx context.Context, user string, maxTweetsNbr int) <-chan *Tweet
// FetchTweets gets tweets for a given user, via the Twitter frontend API. // FetchTweets gets tweets for a given user, via the Twitter frontend API.
func (s *Scraper) FetchTweets(user string, maxTweetsNbr int, cursor string) ([]*Tweet, string, error) { func (s *Scraper) FetchTweets(user string, maxTweetsNbr int, cursor string) ([]*Tweet, string, error) {
if maxTweetsNbr > 200 {
maxTweetsNbr = 200
}
userID, err := s.GetUserIDByScreenName(user) userID, err := s.GetUserIDByScreenName(user)
if err != nil { if err != nil {
return nil, "", err return nil, "", err
} }
return s.FetchTweetsByUserID(userID, maxTweetsNbr, cursor)
}
// FetchTweetsByUserID gets tweets for a given userID, via the Twitter frontend API.
func (s *Scraper) FetchTweetsByUserID(userID string, maxTweetsNbr int, cursor string) ([]*Tweet, string, error) {
if maxTweetsNbr > 200 {
maxTweetsNbr = 200
}
req, err := s.newRequest("GET", "https://api.twitter.com/2/timeline/profile/"+userID+".json") req, err := s.newRequest("GET", "https://api.twitter.com/2/timeline/profile/"+userID+".json")
if err != nil { if err != nil {
return nil, "", err return nil, "", err