-
Notifications
You must be signed in to change notification settings - Fork 59
/
item_comment.go
151 lines (130 loc) · 6.46 KB
/
item_comment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package douyingo
import (
"context"
"net/url"
"github.com/zhangshuai/douyin-go/conf"
)
// ItemCommentListReq 评论列表请求
type ItemCommentListReq struct {
OpenId string // 通过/oauth/access_token/获取,用户唯一标志
AccessToken string // 调用/oauth/access_token/生成的token,此token需要用户授权。
Cursor int64 // 分页游标, 第一页请求cursor是0, response中会返回下一页请求用到的cursor, 同时response还会返回has_more来表明是否有更多的数据。
Count int64 // 每页数量
ItemId string // 视频id
}
// ItemComment 评论列表
type ItemComment struct {
ReplyCommentTotal int32 `json:"reply_comment_total"` // 回复评论数
Top bool `json:"top"` // 是否置顶评论
CommentId string `json:"comment_id"` // 评论id
CommentUserId string `json:"comment_user_id"` // 评论用户id
Content string `json:"content"` // 评论内容
CreateTime int64 `json:"create_time"` // 时间戳
DiggCount int32 `json:"digg_count"` // 点赞数
Avatar string `json:"avatar,omitempty"` // 用户头像url
Nickname string `json:"nick_name,omitempty"` // 用户昵称
}
// ItemCommentListData 评论列表
type ItemCommentListData struct {
List []ItemComment `json:"list"` // 评论列表
Cursor int64 `json:"cursor"` // 用于下一页请求的cursor
HasMore bool `json:"has_more"` // 更多数据
DYError
}
// ItemCommentListRes 评论列表
type ItemCommentListRes struct {
Data ItemCommentListData `json:"data"`
Extra DYExtra `json:"extra"`
}
// ItemCommentList 获取评论列表
func (m *Manager) ItemCommentList(req ItemCommentListReq) (res ItemCommentListRes, err error) {
itemId := url.QueryEscape(req.ItemId)
err = m.client.CallWithJson(context.Background(), &res, "GET", m.url("%s?access_token=%s&open_id=%s&cursor=%d&count=%d&item_id=%s", conf.API_ITEM_COMMENT_LIST, req.AccessToken, req.OpenId, req.Cursor, req.Count, itemId), nil, nil)
return res, err
}
// ItemCommentReplyListReq 评论回复列表请求
type ItemCommentReplyListReq struct {
OpenId string // 通过/oauth/access_token/获取,用户唯一标志
AccessToken string // 调用/oauth/access_token/生成的token,此token需要用户授权。
Cursor int64 // 分页游标, 第一页请求cursor是0, response中会返回下一页请求用到的cursor, 同时response还会返回has_more来表明是否有更多的数据。
Count int64 // 每页的数量,最大不超过20,最小不低于1
ItemId string // 视频id
CommentId string // 评论id
SortType string // 列表排序方式,不传默认按推荐序,可选值:time(时间逆序)、time_asc(时间顺序)
}
// ItemCommentReplyListData 评论回复列表
type ItemCommentReplyListData struct {
List []ItemComment `json:"list"` // 评论回复列表
Cursor int64 `json:"cursor"` // 用于下一页请求的cursor
HasMore bool `json:"has_more"` // 更多数据
DYError
}
// ItemCommentReplyListRes 评论回复列表
type ItemCommentReplyListRes struct {
Data ItemCommentReplyListData `json:"data"`
Extra DYExtra `json:"extra"`
}
// ItemCommentReplyList 获取评论回复列表
func (m *Manager) ItemCommentReplyList(req ItemCommentReplyListReq) (res ItemCommentReplyListRes, err error) {
itemId := url.QueryEscape(req.ItemId)
commentId := url.QueryEscape(req.CommentId)
err = m.client.CallWithJson(context.Background(), &res, "GET", m.url("%s?access_token=%s&open_id=%s&cursor=%d&count=%d&item_id=%s&comment_id=%s&sort_type=%s", conf.API_ITEM_COMMENT_REPLY_LIST, req.AccessToken, req.OpenId, req.Cursor, req.Count, itemId, commentId, req.SortType), nil, nil)
return res, err
}
// ItemCommentReplyReq 回复视频评论请求
type ItemCommentReplyReq struct {
OpenId string // 通过/oauth/access_token/获取,用户唯一标志
AccessToken string // 调用/oauth/access_token/生成的token,此token需要用户授权。
Body ItemCommentReplyBody // 回复视频评论body
}
// ItemCommentReplyBody 回复视频评论
type ItemCommentReplyBody struct {
CommentId string `json:"comment_id,omitempty"` // 需要回复的评论id(如果需要回复的是视频不传此字段)
Content string `json:"content"` // 评论内容
ItemId string `json:"item_id"` // 视频id
}
// ItemCommentReplyData 回复视频评论
type ItemCommentReplyData struct {
CommentId string `json:"comment_id"` // 评论id
Avatar string `json:"avatar"` // 用户头像url
Nickname string `json:"nick_name"` // 用户昵称
DYError
}
// ItemCommentReplyRes 回复视频评论
type ItemCommentReplyRes struct {
Data ItemCommentReplyData `json:"data"`
Extra DYExtra `json:"extra"`
}
// ItemCommentReply 回复视频评论
func (m *Manager) ItemCommentReply(req ItemCommentReplyReq) (res ItemCommentReplyRes, err error) {
err = m.client.CallWithJson(context.Background(), &res, "POST", m.url("%s?access_token=%s&open_id=%s", conf.API_ITEM_COMMENT_REPLY, req.AccessToken, req.OpenId), nil, req.Body)
return res, err
}
// ItemCommentTopReq 置顶视频评论请求
type ItemCommentTopReq struct {
OpenId string // 通过/oauth/access_token/获取,用户唯一标志
AccessToken string // 调用/oauth/access_token/生成的token,此token需要用户授权。
Body ItemCommentTopBody // 回复视频置顶body
}
// ItemCommentTopBody 置顶视频评论
type ItemCommentTopBody struct {
ItemId string `json:"item_id"` // 视频id
CommentId string `json:"comment_id"` // 评论id
Top bool `json:"top"` // true-置顶;false-不置顶
}
// ItemCommentTopData 置顶视频评论
type ItemCommentTopData struct {
DYError
}
// ItemCommentTopRes 置顶视频评论
type ItemCommentTopRes struct {
Data ItemCommentTopData `json:"data"`
Avatar string `json:"avatar"` // 用户头像url
Nickname string `json:"nick_name"` // 用户昵称
Extra DYExtra `json:"extra"`
}
// ItemCommentTop 置顶视频评论
func (m *Manager) ItemCommentTop(req ItemCommentTopReq) (res ItemCommentTopRes, err error) {
err = m.client.CallWithJson(context.Background(), &res, "POST", m.url("%s?access_token=%s&open_id=%s", conf.API_ITEM_COMMENT_TOP, req.AccessToken, req.OpenId), nil, req.Body)
return res, err
}