Code optimization
This commit is contained in:
parent
a4375c3b2d
commit
6c4a1cc054
4 changed files with 28 additions and 42 deletions
31
api.go
31
api.go
|
|
@ -90,34 +90,3 @@ func (s *Scraper) GetGuestToken() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserIDByScreenName from API
|
||||
func (s *Scraper) GetUserIDByScreenName(screenName string) (string, error) {
|
||||
id, ok := cacheIDs.Load(screenName)
|
||||
if ok {
|
||||
return id.(string), nil
|
||||
}
|
||||
|
||||
var jsn user
|
||||
req, err := http.NewRequest("GET", "https://api.twitter.com/graphql/4S2ihIKfF3xhp-ENxvUAfQ/UserByScreenName?variables=%7B%22screen_name%22%3A%22"+screenName+"%22%2C%22withHighlightedLabel%22%3Atrue%7D", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = s.RequestAPI(req, &jsn)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(jsn.Errors) > 0 {
|
||||
return "", fmt.Errorf("%s", jsn.Errors[0].Message)
|
||||
}
|
||||
|
||||
if jsn.Data.User.RestID == "" {
|
||||
return "", fmt.Errorf("rest_id not found")
|
||||
}
|
||||
|
||||
cacheIDs.Store(screenName, jsn.Data.User.RestID)
|
||||
|
||||
return jsn.Data.User.RestID, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue