實作:管道

本頁面說明如何使用 YouTube Data API (v3) 執行與擷取及更新頻道資料相關的功能。channel 資源包含播放清單 ID,可識別頻道上傳和喜歡的影片。如要在呼叫 channels.list 方法時擷取這項資訊,請確認 part 參數值包含 contentDetails 資源部分。

擷取管道相關資訊

呼叫 channels.list 方法,擷取特定頻道的資訊。你可以透過下列幾種方式找出頻道:

設定頻道的品牌資訊

這個範例會更新頻道的品牌宣傳選項。這個範例包含兩個步驟:

  • 步驟 1:擷取頻道的品牌宣傳選項

    呼叫 channels.list 方法,並將 part 參數值設為 brandingSettings,mine 參數值設為 true。

    https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list?
            part=brandingSettings
            &mine=true

    應用程式可以顯示擷取的設定,讓使用者修改要更新的設定。

  • 步驟 2:更新頻道的品牌宣傳選項

    呼叫 channels.list 方法並設定下列值:

    • 將 id 屬性設為頻道的專屬 YouTube 頻道 ID。您可以從步驟 1 的 API 回應中擷取 ID。
    • 將 part 參數值設為 brandingSettings。

    點選下方的 API Explorer 連結,即可建立具有下列品牌設定的 channel 資源:

    {
      "id": "CHANNEL_ID",
      "brandingSettings": {
        "channel": {
          "description": "A great channel to be enjoyed by all.",
          "moderateComments": true,
          "showRelatedChannels": true,
          "showBrowseView": true,
          "featuredChannelsTitle": "Featured Channel Stuff",
          "featuredChannelsUrls": [
            "UC_x5XG1OV2P6uZZ5FSM9Ttw",
            "UCBR8-60-B28hp2BmDPdntcQ",
            "UCK8sQmJBp8GCxrOtXWBpyEA"
          ],
          "profileColor": "#006600"
        }
      }
    }

    如要在 APIs Explorer 中完成要求,您需要將 id 屬性的值設為已驗證使用者頻道的頻道 ID。此外,您也應設定圖片屬性,使其符合目前的設定。

    https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.update?
            part=brandingSettings
    

管理頻道版面

API 支援 channelSections.list、channelSections.insert、channelSections.update 和 channelSections.delete 方法,可用於管理頻道版面。頻道版面是一組在頻道上精選的影片。舉例來說,版面可以包含頻道最新上傳的影片、最熱門的上傳影片,或一或多個播放清單中的影片。

以下範例會擷取 Google 官方 YouTube 頻道的頻道版面。這項要求會呼叫 channelSections.list 方法,並將 channelId 參數值設為 UCK8sQmJBp8GCxrOtXWBpyEA,也就是 Google 頻道的頻道 ID。

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channelSections.list?
part=snippet,contentDetails
&channelId=UCK8sQmJBp8GCxrOtXWBpyEA

如果將 mine 參數值設為 true,而不是使用 channelId 參數,則這項要求需要授權。這個參數表示您要擷取目前已驗證使用者頻道的頻道版面。

上傳及設定頻道浮水印圖片

你可以呼叫 watermarks.set 方法上傳浮水印圖片,並為頻道設定浮水印。播放指定頻道的影片時,就會顯示該圖片。你也可以指定圖片連結的目標頻道,以及浮水印顯示的時間和時長。

watermarks.unset 方法會刪除頻道的浮水印圖片。

很抱歉,這項查詢無法使用 APIs Explorer 測試,因為 APIs Explorer 不支援上傳媒體檔案,而這是這個方法的要求。