本頁將說明如何使用 YouTube Data API (v3) 執行擷取及更新頻道資料的相關函式。channel
資源內含播放清單 ID,可識別頻道上傳和喜歡的影片。如要在呼叫 channels.list
方法時擷取這項資訊,請確認 part
參數值包含 contentDetails
資源部分。
擷取頻道相關資訊
呼叫 channels.list
方法,以擷取特定頻道的相關資訊。識別頻道的方法有以下幾種:
-
將
mine
參數值設為true
,即可擷取目前已驗證使用者的 YouTube 頻道資訊。您的要求必須使用 OAuth 2.0 授權。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list? part=snippet,contentDetails,brandingSettings &mine=true
-
將
forUsername
參數設為 YouTube 使用者名稱,即可擷取與該使用者名稱相關聯的頻道資訊。本例會將forUsername
參數值設為Google
,以擷取 Google 官方 YouTube 頻道的資訊。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list? part=snippet,contentDetails &forUsername=Google
-
將
id
參數設為 YouTube 頻道 ID,此 ID 可用來識別您要擷取資訊的管道。這個範例會將id
參數設為UCK8sQmJBp8GCxrOtXWBpyEA
,這樣也會識別 Google 的官方 YouTube 頻道。https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list? part=snippet,contentDetails &id=UCK8sQmJBp8GCxrOtXWBpyEA
設定頻道的品牌宣傳資訊
本例將更新頻道的品牌宣傳選項。此範例包含兩個步驟:
-
步驟 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
方法並設定下列值:下列 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 不支援上傳媒體檔案的功能。