Merge pull request #95 from windowsdeveloperwannabe/tweets-by-id
Fetch tweets by userID
This commit is contained in:
commit
cd3e612419
1 changed files with 9 additions and 4 deletions
13
tweets.go
13
tweets.go
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue