Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Fix trends
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Sheiko committed May 30, 2023
1 parent ec6e8f3 commit 7f423f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions trends.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "fmt"

// GetTrends return list of trends.
func (s *Scraper) GetTrends() ([]string, error) {
req, err := s.newRequest("GET", "https://twitter.com/i/api/2/guide.json")
req, err := s.newRequest("GET", "https://api.twitter.com/2/guide.json")
if err != nil {
return nil, err
}
Expand All @@ -17,9 +17,14 @@ func (s *Scraper) GetTrends() ([]string, error) {
req.URL.RawQuery = q.Encode()

var jsn timeline
s.setBearerToken(bearerToken2)
curBearerToken := s.bearerToken
if curBearerToken != bearerToken2 {
s.setBearerToken(bearerToken2)
}
err = s.RequestAPI(req, &jsn)
s.setBearerToken(bearerToken)
if curBearerToken != bearerToken2 {
s.setBearerToken(curBearerToken)
}
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion trends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func TestGetTrends(t *testing.T) {
scraper := twitterscraper.New()
trends, err := scraper.GetTrends()
if err != nil {
t.Error(err)
t.Fatal(err)
}

if len(trends) != 20 {
Expand Down

0 comments on commit 7f423f1

Please sign in to comment.