REST Resource: comments

資源:留言

comment 資源包含影片或貼文的單一 YouTube 留言資訊。留言可以是頂層留言,也可以是對頂層留言的回覆。

貼文留言功能目前處於前測階段,僅限特定發布合作夥伴 (已核准的 Google Cloud 專案) 使用。我們預計在 2027 年正式發布,屆時將開放更多公開 API 存取權。

JSON 表示法
{
  "kind": string,
  "etag": string,
  "id": string,
  "snippet": {
    "channelId": string,
    "videoId": string,
    "postId": string,
    "textDisplay": string,
    "textOriginal": string,
    "parentId": string,
    "authorDisplayName": string,
    "authorProfileImageUrl": string,
    "authorChannelUrl": string,
    "authorChannelId": {
      "value": string
    },
    "canRate": boolean,
    "viewerRating": enum,
    "likeCount": integer,
    "moderationStatus": enum (ModerationStatus),
    "publishedAt": string,
    "updatedAt": string,
    "imageUrl": string
  }
}
欄位
kind

string

識別這是哪種資源。值:固定字串 "youtube#comment"。

etag

string

這項資源的 Etag。

id

string

YouTube 用來識別留言的專屬 ID。

snippet

object

snippet 物件包含留言的基本詳細資料。

snippet.channelId

string

與留言相關聯的 YouTube 頻道 ID (留言所屬影片或貼文的頻道)。

snippet.videoId

string

留言提及的影片 ID (如有)。

API 只會針對 commentThread 資源中的留言傳回這個欄位,格式為 snippet.topLevelComment 和 replies.comments[]。

snippet.postId

string

留言所指的貼文 ID (如有)。

API 只會針對 commentThread 資源中的留言傳回這個欄位,格式為 snippet.topLevelComment 和 replies.comments[]。這個欄位僅適用於核准的 Google 雲端專案。

snippet.textDisplay

string

留言文字,格式為 HTML 或純文字,視 comments.list 和 commentThreads.list 要求中的 textFormat 參數而定 (或 comments.insert 和 comments.update 回應中的純文字)。

snippet.textOriginal

string

留言最初發布或上次更新時的原始文字。

snippet.parentId

string

上層頂層留言的專屬 ID。只有在留言是回覆其他留言時,才會設定這個屬性。

snippet.authorDisplayName

string

留言者的顯示名稱。

snippet.authorProfileImageUrl

string

留言者顯示圖片的網址。

snippet.authorChannelUrl

string

留言作者的 YouTube 頻道網址 (如有)。

snippet.authorChannelId

object

封裝留言作者 YouTube 頻道的相關資訊 (如有)。

snippet.authorChannelId.value

string

留言作者的 YouTube 頻道 ID (如有)。

snippet.canRate

boolean

指出檢視者是否能對留言評分。

snippet.viewerRating

enum

檢視者對這則留言的評分。

這個列舉欄位的有效值如下:

  • none
  • like
  • dislike
snippet.likeCount

integer (uint32 format)

留言獲得的喜歡 (正面評價) 總數。

snippet.moderationStatus

enum (ModerationStatus)

留言的管理狀態。只要傳回的留言留待審核 (heldForReview) 或標記為垃圾內容 (likelySpam),系統就會填入這個屬性,並略過已發布的留言。

snippet.publishedAt

string

留言最初發布的日期和時間。這個值是以 ISO 8601 格式指定。

snippet.updatedAt

string

上次更新留言的日期和時間。這個值是以 ISO 8601 格式指定。

snippet.imageUrl

string

僅供輸出。留言中附加的圖片或 GIF 動畫網址 (如有)。只有在留言包含圖片或 GIF 時,才會顯示這項屬性。網址會以已簽署連結的形式提供,存留時間 (TTL) 為六小時,並在擷取後六小時到期。

方法

delete

刪除留言。

insert

建立現有留言的回覆。

list

傳回符合 API 要求參數的留言清單。

setModerationStatus

設定一或多則留言的管理狀態。

update

修改留言。