add SearchLive SearchPhotos SearchVideos
This commit is contained in:
parent
c9ba00cad7
commit
7363f676bf
3 changed files with 51 additions and 0 deletions
|
|
@ -65,6 +65,11 @@ func main() {
|
||||||
|
|
||||||
The search ends if we have 50 tweets.
|
The search ends if we have 50 tweets.
|
||||||
|
|
||||||
|
### Search tweet in realtime
|
||||||
|
```golang
|
||||||
|
scraper.SearchLive(true)
|
||||||
|
```
|
||||||
|
|
||||||
See [Rules and filtering](https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators) for build standard queries.
|
See [Rules and filtering](https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators) for build standard queries.
|
||||||
|
|
||||||
### Get profile
|
### Get profile
|
||||||
|
|
|
||||||
40
scraper.go
40
scraper.go
|
|
@ -15,6 +15,7 @@ type Scraper struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
guestToken string
|
guestToken string
|
||||||
includeReplies bool
|
includeReplies bool
|
||||||
|
searchMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultScraper *Scraper
|
var defaultScraper *Scraper
|
||||||
|
|
@ -26,6 +27,45 @@ func New() *Scraper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSearchLive enable/disable realtime search
|
||||||
|
func (s *Scraper) SearchLive(srctype bool) *Scraper {
|
||||||
|
if srctype {
|
||||||
|
s.searchMode = "live"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSearchLive wrapper for default SetSearchLive
|
||||||
|
func SearchLive(srctype bool) *Scraper {
|
||||||
|
return defaultScraper.SearchLive(srctype)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSearchPhotos filter search for photos only
|
||||||
|
func (s *Scraper) SearchPhotos(srctype bool) *Scraper {
|
||||||
|
if srctype {
|
||||||
|
s.searchMode = "image"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSearchPhotos wrapper for default SetSearchPhotos
|
||||||
|
func SearchPhotos(srctype bool) *Scraper {
|
||||||
|
return defaultScraper.SearchPhotos(srctype)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSearchVideos filter search for videos only
|
||||||
|
func (s *Scraper) SearchVideos(srctype bool) *Scraper {
|
||||||
|
if srctype {
|
||||||
|
s.searchMode = "video"
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSearchVideos wrapper for default SetSearchVideos
|
||||||
|
func SearchVideos(srctype bool) *Scraper {
|
||||||
|
return defaultScraper.SearchVideos(srctype)
|
||||||
|
}
|
||||||
|
|
||||||
// WithReplies enable/disable load timeline with tweet replies
|
// WithReplies enable/disable load timeline with tweet replies
|
||||||
func (s *Scraper) WithReplies(b bool) *Scraper {
|
func (s *Scraper) WithReplies(b bool) *Scraper {
|
||||||
s.includeReplies = b
|
s.includeReplies = b
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,12 @@ func (s *Scraper) FetchSearchTweets(query string, maxTweetsNbr int, cursor strin
|
||||||
if cursor != "" {
|
if cursor != "" {
|
||||||
q.Add("cursor", cursor)
|
q.Add("cursor", cursor)
|
||||||
}
|
}
|
||||||
|
if s.searchMode == "live" {
|
||||||
|
q.Add("tweet_search_mode", s.searchMode)
|
||||||
|
} else {
|
||||||
|
q.Add("result_filter", s.searchMode)
|
||||||
|
}
|
||||||
|
|
||||||
req.URL.RawQuery = q.Encode()
|
req.URL.RawQuery = q.Encode()
|
||||||
|
|
||||||
var timeline timeline
|
var timeline timeline
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue