feat:获取用户主页功能 (#122)

增加读取用户的个人主页的信息
This commit is contained in:
CooperGuo
2025-09-20 22:20:58 +08:00
committed by GitHub
parent eafd973d75
commit 5f412a6bc5
8 changed files with 243 additions and 0 deletions

View File

@@ -49,6 +49,13 @@ type FeedsListResponse struct {
Count int `json:"count"`
}
// UserProfileResponse 用户主页响应
type UserProfileResponse struct {
UserBasicInfo xiaohongshu.UserBasicInfo `json:"userBasicInfo"`
Interactions []xiaohongshu.UserInteractions `json:"interactions"`
Feeds []xiaohongshu.Feed `json:"feeds"`
}
// CheckLoginStatus 检查登录状态
func (s *XiaohongshuService) CheckLoginStatus(ctx context.Context) (*LoginStatusResponse, error) {
b := newBrowser()
@@ -205,6 +212,30 @@ func (s *XiaohongshuService) GetFeedDetail(ctx context.Context, feedID, xsecToke
return response, nil
}
// UserProfile 获取用户信息
func (s *XiaohongshuService) UserProfile(ctx context.Context, userID, xsecToken string) (*UserProfileResponse, error) {
b := newBrowser()
defer b.Close()
page := b.NewPage()
defer page.Close()
action := xiaohongshu.NewUserProfileAction(page)
result, err := action.UserProfile(ctx, userID, xsecToken)
if err != nil {
return nil, err
}
response := &UserProfileResponse{
UserBasicInfo: result.UserBasicInfo,
Interactions: result.Interactions,
Feeds: result.Feeds,
}
return response, nil
}
// PostCommentToFeed 发表评论到Feed
func (s *XiaohongshuService) PostCommentToFeed(ctx context.Context, feedID, xsecToken, content string) (*PostCommentResponse, error) {
// 使用非无头模式以便查看操作过程