feat: add IsBlueVerified to profile responses

Add support for Twitter's blue verification status in profile responses:
- Add IsBlueVerified field to user struct in GetProfile response
- Update parseProfile and parseProfileV2 to include blue verification status
- Add ProfileImageShape and HasGraduatedAccess fields to profile responses

This change ensures the API correctly returns blue verification status for both direct profile queries and timeline responses.
This commit is contained in:
Brendan Playford 2025-01-22 11:14:03 -08:00
parent 7226460e05
commit 388445d4c2
No known key found for this signature in database
GPG key ID: 663CFC091C1BDFBD
2 changed files with 32 additions and 24 deletions

View file

@ -50,9 +50,10 @@ type user struct {
Data struct {
User struct {
Result struct {
RestID string `json:"rest_id"`
Legacy legacyUser `json:"legacy"`
Message string `json:"message"`
RestID string `json:"rest_id"`
Legacy legacyUser `json:"legacy"`
Message string `json:"message"`
IsBlueVerified bool `json:"is_blue_verified"`
} `json:"result"`
} `json:"user"`
} `json:"data"`
@ -118,7 +119,9 @@ func (s *Scraper) GetProfile(username string) (Profile, error) {
return Profile{}, fmt.Errorf("either @%s does not exist or is private", username)
}
return parseProfile(jsn.Data.User.Result.Legacy), nil
profile := parseProfile(jsn.Data.User.Result.Legacy)
profile.IsBlueVerified = jsn.Data.User.Result.IsBlueVerified
return profile, nil
}
func (s *Scraper) GetProfileByID(userID string) (Profile, error) {
@ -175,7 +178,9 @@ func (s *Scraper) GetProfileByID(userID string) (Profile, error) {
return Profile{}, fmt.Errorf("either @%s does not exist or is private", userID)
}
return parseProfile(jsn.Data.User.Result.Legacy), nil
profile := parseProfile(jsn.Data.User.Result.Legacy)
profile.IsBlueVerified = jsn.Data.User.Result.IsBlueVerified
return profile, nil
}
// GetUserIDByScreenName from API

41
util.go
View file

@ -385,25 +385,28 @@ func parseProfile(user legacyUser) Profile {
func parseProfileV2(user userResult) Profile {
u := user.Legacy
profile := Profile{
Avatar: u.ProfileImageURLHTTPS,
Banner: u.ProfileBannerURL,
Biography: u.Description,
FollowersCount: u.FollowersCount,
FollowingCount: u.FavouritesCount,
FriendsCount: u.FriendsCount,
IsVerified: u.Verified,
LikesCount: u.FavouritesCount,
ListedCount: u.ListedCount,
Location: u.Location,
Name: u.Name,
PinnedTweetIDs: u.PinnedTweetIdsStr,
TweetsCount: u.StatusesCount,
URL: "https://twitter.com/" + u.ScreenName,
UserID: user.ID,
Username: u.ScreenName,
Sensitive: u.PossiblySensitive,
Following: u.Following,
FollowedBy: u.FollowedBy,
Avatar: u.ProfileImageURLHTTPS,
Banner: u.ProfileBannerURL,
Biography: u.Description,
FollowersCount: u.FollowersCount,
FollowingCount: u.FavouritesCount,
FriendsCount: u.FriendsCount,
IsVerified: u.Verified,
IsBlueVerified: user.IsBlueVerified,
ProfileImageShape: user.ProfileImageShape,
HasGraduatedAccess: user.HasGraduatedAccess,
LikesCount: u.FavouritesCount,
ListedCount: u.ListedCount,
Location: u.Location,
Name: u.Name,
PinnedTweetIDs: u.PinnedTweetIdsStr,
TweetsCount: u.StatusesCount,
URL: "https://twitter.com/" + u.ScreenName,
UserID: user.ID,
Username: u.ScreenName,
Sensitive: u.PossiblySensitive,
Following: u.Following,
FollowedBy: u.FollowedBy,
}
tm, err := time.Parse(time.RubyDate, u.CreatedAt)