Posts

posts 資源及其方法目前處於前測階段,僅限特定推出合作夥伴 (已核准的 Google Cloud 雲端專案) 存取。我們預計在 2027 年正式發布,屆時將開放更多公開 API 存取權。

post 資源代表 YouTube 貼文。這個 API 支援純文字貼文和圖片貼文,後者包含 1 到 10 張圖片和選填文字。

方法

API 支援下列 posts 資源方法:

list
傳回符合 API 要求參數的貼文清單。
insert
建立及發布純文字或圖片貼文。
update
更新貼文文字。
刪除
刪除貼文。
imageUpload
上傳圖片並傳回權杖,用於將圖片附加至新貼文。

資源表示法

下列 JSON 結構顯示 posts 資源的格式:

{
  "kind": "youtube#post",
  "etag": etag,
  "id": string,
  "snippet": {
    "channelId": string,
    "textDisplay": string,
    "publishTime": datetime
  },
  "statistics": {
    "likeCount": long,
    "commentCount": long
  },
  "attachments": {
    "imageAttachments": [
      {
        "uploadToken": string,
        "imagePreview": {
          "url": string,
          "width": integer,
          "height": integer
        }
      }
    ]
  },
  "status": {
    "processingStatus": string,
    "publishingStatus": string,
    "archiveState": string
  }
}

屬性

下表定義這項資源中顯示的屬性:

屬性
kind string
識別 API 資源的類型。值為 youtube#post。
etag etag
這項資源的 Etag。
id string
YouTube 用來識別貼文的專屬 ID。
snippet object
snippet 物件包含貼文的基本詳細資料,例如頻道和文字。
snippet.channelId string
發布貼文的頻道 ID。

插入貼文時,必須提供這項屬性。
snippet.textDisplay string
貼文文字。

插入純文字貼文或更新貼文時,必須提供這個屬性;插入圖片貼文時,則可選擇是否提供。
snippet.publishTime datetime
貼文發布的日期和時間。這個值是以 ISO 8601 格式指定。
statistics object
statistics 物件包含貼文的統計資料。API 只會在 posts.list 回應中傳回這個物件。
statistics.likeCount long
貼文獲得的按讚數。
statistics.commentCount long
貼文的留言數。
attachments object
attachments 物件包含貼文附加的圖片。
attachments.imageAttachments[] list
貼文附加的圖片清單。圖片貼文包含 1 到 10 張圖片;純文字貼文則會省略 attachments 物件。
attachments.imageAttachments[].uploadToken string
用於識別您透過 posts.imageUpload 方法上傳圖片的權杖。

請在插入貼文時設定這個屬性。API 不會傳回這項屬性。
attachments.imageAttachments[].imagePreview object
YouTube 提供的圖片相關資訊。這個物件由 API 設定,您無法設定。

YouTube 會根據貼文顯示位置,在預覽畫面中顯示不同顯示比例的圖片,例如裁剪成正方形。
attachments.imageAttachments[].imagePreview.url string
圖片的網址。
attachments.imageAttachments[].imagePreview.width integer
圖片寬度,以像素為單位。
attachments.imageAttachments[].imagePreview.height integer
圖片高度,以像素為單位。
status object
status 物件包含貼文的處理、發布和封存狀態資訊。
status.processingStatus string
貼文的處理狀態。

這項屬性的有效值如下:
  • complete:貼文已處理完畢。
  • processing:YouTube 正在準備發布貼文。
status.publishingStatus string
貼文的發布狀態。

這項屬性的有效值如下:
  • published:貼文已發布。
  • scheduled:貼文已排定發布時間,只有擁有者看得到。
status.archiveState string
貼文的封存狀態。

這項屬性的有效值如下:
  • archived:貼文已封存,只有擁有者可以查看。
  • evergreen:貼文未封存,也未排定封存。
  • scheduledToArchive:貼文已排定封存。