add GetTweetReplies method

This commit is contained in:
Valentine 2024-08-01 17:39:06 +03:00
parent e053917d34
commit f86a0ea59d
6 changed files with 232 additions and 7 deletions

View file

@ -22,6 +22,7 @@ You can use this library to get tweets, profiles, and trends trivially.
- [Log out](#log-out)
- [Methods](#methods)
- [Get tweet](#get-tweet)
- [Get tweet replies](#get-tweet-replies)
- [Get user tweets](#get-user-tweets)
- [Get user medias](#get-user-medias)
- [Get bookmarks](#get-bookmarks)
@ -212,6 +213,44 @@ scraper.Logout()
tweet, err := scraper.GetTweet("1328684389388185600")
```
### Get tweet replies
150 requests / 15 minutes
Returns by ~5-10 tweets and multiple cursors one for each thread.
```golang
var cursor string
tweets, cursors, err := scraper.GetTweetReplies("1328684389388185600", cursor)
```
To get all replies and replies of replies for tweet you can iterate for all cursors. To get only direct replies check if `cursor.ThreadID` is equal your tweet id.
```golang
tweets, cursors, err := testScraper.GetTweetReplies("1328684389388185600", "")
if err != nil {
panic(err)
}
for {
if len(cursors) > 0 {
var cursor *twitterscraper.ThreadCursor
cursor, cursors = cursors[0], cursors[1:]
moreTweets, moreCursors, err := testScraper.GetTweetReplies(tweetId, cursor.Cursor)
if err != nil {
// you can check here if rate limited, await and repeat request
panic(err)
}
tweets = append(tweets, moreTweets...)
if len(moreCursors) > 0 {
cursors = append(cursors, moreCursors...)
}
} else {
break
}
}
```
### Get user tweets
150 requests / 15 minutes