CommentThreads

commentThread 资源包含有关 YouTube 评论会话的信息,其中包括一条顶级评论和对该评论的回复(如果有)。commentThread 资源表示对视频的评论。

顶层评论和回复实际上是嵌套在 commentThread 资源中的 comment 资源。commentThread 资源不一定包含对评论的所有回复,并且如果您想检索特定评论的所有回复,则需要使用 comments.list 方法。某些评论没有回复。

方法

对于 commentThreads 资源,该 API 支持以下方法:

list
返回与 API 请求参数匹配的评论线程列表。立即试用
insert
创建新的顶级评论。如需向现有评论添加回复,请改用 comments.insert 方法。立即试用

资源表示法

JSON 结构显示了 commentThreads 资源的格式:

{
  "kind": "youtube#commentThread",
  "etag": etag,
  "id": string,
  "snippet": {
    "channelId": string,
    "videoId": string,
    "topLevelComment": comments Resource,
    "canReply": boolean,
    "totalReplyCount": unsigned integer,
    "isPublic": boolean
  },
  "replies": {
    "comments": [
      comments Resource
    ]
  }
}

属性

下表定义了此资源中显示的属性:

属性
kind string
标识 API 资源的类型。其值为 youtube#commentThread
etag etag
此资源的 Etag。
id string
YouTube 用于唯一标识评论会话的 ID。
snippet object
snippet 对象包含有关评论会话的基本详情。它还包含线程的顶级注释,这是一种 comment 资源。
snippet.channelId string
与会话串中的评论相关联的 YouTube 频道。snippet.videoId 属性用于标识视频。
snippet.videoId string
评论所提及的视频的 ID。
snippet.topLevelComment object
消息串的顶级评论。该属性的值是 comment 资源。
snippet.canReply boolean
此设置用于指明当前观看者是否可以回复此会话。
snippet.totalReplyCount unsigned integer
用户针对顶级评论提交的回复总数。
snippet.isPublic boolean
此设置用于指明该会话(包括其中的所有评论和评论回复)是否向所有 YouTube 用户显示。
replies object
replies 对象是一个容器,其中包含评论的回复列表(如果存在)。replies.comments 属性表示注释列表本身。
replies.comments[] list
由顶级评论的一条或多条回复组成的列表。列表中的每一项都是 comment 资源。

该列表中包含的回复数量有限。除非列表中的项数等于 snippet.totalReplyCount 属性的值,否则该回复列表只是顶级评论可用回复总数的一部分。要检索顶级评论的所有回复,您需要调用 comments.list 方法并使用 parentId 请求参数来标识要检索其回复的评论。