เรากำลังอัปเดต Data API ให้สอดคล้องกับวิธีที่ YouTube นับยอดดูสำหรับ Shorts
ดูข้อมูลเพิ่มเติม
การใช้งาน: คำบรรยายแทนเสียง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ตัวอย่างต่อไปนี้แสดงวิธีใช้ YouTube Data API (v3) เพื่อดำเนินการที่เกี่ยวข้องกับคำบรรยายแทนเสียง
เรียกข้อมูลรายการแทร็กคำบรรยายแทนเสียงของวิดีโอ
สร้างแทร็กคำบรรยายแทนเสียง
ไม่สามารถทดสอบการค้นหานี้โดยใช้โปรแกรมสำรวจ API ได้ เนื่องจากโปรแกรมสำรวจ API ไม่รองรับการอัปโหลดไฟล์ ซึ่งเป็นข้อกําหนดของวิธีการนี้
คุณสามารถใช้เมธอด captions.insert
ของ API เพื่ออัปโหลดแทร็กคำบรรยายแทนเสียงใหม่สำหรับวิดีโอ เมื่ออัปโหลดแทร็ก คุณต้องระบุค่าสำหรับพร็อพเพอร์ตี้ทรัพยากร caption
ต่อไปนี้
ตัวเลือกเพิ่มเติมต่อไปนี้จะพร้อมใช้งานเมื่ออัปโหลดแทร็กคำบรรยายแทนเสียง
-
หากคุณตั้งค่าพารามิเตอร์ sync
เป็น true
ทาง YouTube จะไม่สนใจเวลาโค้ดที่อยู่ในไฟล์คำบรรยายที่อัปโหลดและสร้างเวลาโค้ดใหม่สำหรับคำบรรยายแทนเสียง
คุณควรตั้งค่าพารามิเตอร์ sync
เป็น true
หากคุณอัปโหลดข้อความถอดเสียงที่ไม่มีรหัสเวลา หรือหากคุณสงสัยว่ารหัสเวลาในไฟล์ไม่ถูกต้องและต้องการให้ YouTube พยายามแก้ไข
-
หากคุณตั้งค่าพร็อพเพอร์ตี้ snippet.isDraft
ของทรัพยากร caption
เป็น true
แทร็กจะไม่แสดงต่อสาธารณะ
ดูตัวอย่างโค้ดได้จากเอกสารประกอบของเมธอด captions.insert
ดาวน์โหลดแทร็กคำบรรยายแทนเสียง
ทดสอบการค้นหานี้โดยใช้โปรแกรมสำรวจ API ไม่ได้ เนื่องจากโปรแกรมสำรวจ API ไม่รองรับการดาวน์โหลดไฟล์
หากต้องการดาวน์โหลดแทร็กคำบรรยายแทนเสียงที่เฉพาะเจาะจง ให้เรียกใช้เมธอด captions.download
ตั้งค่าพารามิเตอร์ id
เป็นรหัสแทร็กคำบรรยายแทนเสียงของ YouTube ที่ระบุแทร็กคำบรรยายแทนเสียงที่คุณดาวน์โหลดอยู่โดยเฉพาะ คำขอของคุณต้องได้รับสิทธิ์โดยใช้ OAuth 2.0
API เวอร์ชัน 3 รองรับตัวเลือกต่อไปนี้
-
หากต้องการระบุว่าควรแสดงผลแทร็กคำบรรยายแทนเสียงในรูปแบบที่เฉพาะเจาะจง ให้ตั้งค่าพารามิเตอร์ tfmt
เพื่อระบุรูปแบบที่ต้องการ คําจํากัดความพารามิเตอร์จะแสดงค่าที่รองรับ
-
หากต้องการเรียกข้อมูลคำแปลของแทร็กคำบรรยาย ให้ตั้งค่าพารามิเตอร์ tlang
เป็นรหัสภาษาแบบ 2 ตัวอักษรของ ISO 639-1 ที่ระบุภาษาของคำบรรยายที่ต้องการ คำแปลสร้างขึ้นโดยใช้การแปลด้วยคอมพิวเตอร์ เช่น Google แปลภาษา
ดูตัวอย่างโค้ดได้จากเอกสารประกอบของเมธอด captions.download
อัปเดตแทร็กคำบรรยายแทนเสียง
API นี้รองรับการเปลี่ยนสถานะฉบับร่างของแทร็กคำบรรยายแทนเสียง อัปโหลดแทร็กคำบรรยายแทนเสียงใหม่สำหรับไฟล์ หรือทั้ง 2 อย่าง
คุณสามารถใช้โปรแกรมสำรวจ API เพื่อทดสอบความสามารถในการเปลี่ยนสถานะฉบับร่างของแทร็ก อย่างไรก็ตาม คุณไม่สามารถใช้โปรแกรมสำรวจ API เพื่ออัปเดตแทร็กคำบรรยายแทนเสียงจริงได้ เนื่องจากเครื่องมือไม่รองรับการอัปโหลดไฟล์
คำขอด้านล่างจะดึงข้อมูลรายการคำบรรยายแทนเสียงของวิดีโอในช่อง YouTube ของ Google Stories
คำขอจะอัปเดตสถานะฉบับร่างของแทร็กคำบรรยายแทนเสียงเป็น true
ซึ่งหมายความว่าแทร็กจะไม่แสดงต่อสาธารณะ หากต้องการส่งคำขอในเครื่องมือสํารวจ API ให้เสร็จสมบูรณ์ คุณต้องตั้งค่าค่าของพร็อพเพอร์ตี้ id
เพื่อระบุแทร็กคำบรรยายแทนเสียง
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.captions.update?
part=snippet
ดูตัวอย่างโค้ดได้จากเอกสารประกอบของเมธอด captions.update
ลบแทร็กคำบรรยายแทนเสียง
ตัวอย่างนี้แสดงวิธีลบแทร็กคำบรรยายแทนเสียง ตัวอย่างนี้มีขั้นตอนดังนี้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-11-23 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2024-11-23 UTC"],[[["\u003cp\u003eThis document provides instructions on how to use the YouTube Data API (v3) to manage video captions.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve a list of caption tracks for a specific video using the \u003ccode\u003ecaptions.list\u003c/code\u003e method, requiring OAuth 2.0 authorization.\u003c/p\u003e\n"],["\u003cp\u003eUploading a new caption track to a video is achieved using the \u003ccode\u003ecaptions.insert\u003c/code\u003e method, requiring the \u003ccode\u003esnippet.videoId\u003c/code\u003e, \u003ccode\u003esnippet.language\u003c/code\u003e, and \u003ccode\u003esnippet.name\u003c/code\u003e properties to be set.\u003c/p\u003e\n"],["\u003cp\u003eDownloading a specific caption track is possible via the \u003ccode\u003ecaptions.download\u003c/code\u003e method, including options to specify the desired format and retrieve a translated version.\u003c/p\u003e\n"],["\u003cp\u003eThe API allows for updating a caption track's draft status and even deleting it completely using the \u003ccode\u003ecaptions.update\u003c/code\u003e and \u003ccode\u003ecaptions.delete\u003c/code\u003e methods respectively.\u003c/p\u003e\n"]]],["The YouTube Data API (v3) facilitates caption management. Key actions include: retrieving caption track lists for a video via `captions.list`; creating new tracks with `captions.insert`, specifying video ID, language, and name; downloading tracks with `captions.download`, allowing format and language selection; updating track status or file with `captions.update`; and deleting tracks using `captions.delete` after retrieving the track ID. Uploading caption files cannot be tested in the APIs Explorer.\n"],null,["# Implementation: Captions\n\nThe following examples show how to use the YouTube Data API (v3) to perform functions related to captions.\n\nRetrieve a list of caption tracks for a video\n---------------------------------------------\n\nTo retrieve a list of caption tracks that are available for a specific video, call the [captions.list](/youtube/v3/docs/captions/list) method. Set the [videoId](/youtube/v3/docs/captions/list#videoId) parameter value to the YouTube video ID that uniquely identifies the video for which you are retrieving captions. Your request must be authorized using OAuth 2.0.\n\nThe request below retrieves a list of captions for a video on the Google Stories YouTube channel: \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.captions.list?\npart=snippet\n&videoId=PRU2ShMzQRg\n```\n\nSee the [captions.list](/youtube/v3/docs/captions/list#usage) method's documentation for code samples.\n\nCreate a caption track\n----------------------\n\nThis query cannot be tested using the APIs Explorer because the APIs Explorer does not support the ability to upload files, which is a requirement for this method.\n\nYou can use the API's [captions.insert](/youtube/v3/docs/captions/insert) method to upload a new caption track for a video. When uploading a track, you must specify a value for the following `caption` resource properties:\n\n\u003cbr /\u003e\n\n- [snippet.videoId](/youtube/v3/docs/captions#snippet.videoId) - This identifies the video to which the caption track is being added.\n- [snippet.language](/youtube/v3/docs/captions#snippet.language) - The language of the caption track.\n- [snippet.name](/youtube/v3/docs/captions#snippet.name) - The name of the caption track.\n\n\u003cbr /\u003e\n\nThe following additional options are available when uploading a caption track:\n\n- If you set the [sync](/youtube/v3/docs/captions/insert#sync) parameter to `true`, YouTube will disregard any time codes that are in the uploaded caption file and generate new time codes for the captions.\n\n You should set the [sync](/youtube/v3/docs/captions/insert#sync) parameter to `true` if you are uploading a transcript, which has no time codes, or if you suspect the time codes in your file are incorrect and want YouTube to try to fix them.\n- If you set the `caption` resource's [snippet.isDraft](/youtube/v3/docs/captions#snippet.isDraft) property to `true`, the track will not be publicly visible.\n\nSee the [captions.insert](/youtube/v3/docs/captions/insert#examples) method's documentation for code samples.\n\nDownload a caption track\n------------------------\n\nThis query cannot be tested using the APIs Explorer because the APIs Explorer does not support the ability to download files.\n\nTo download a specific caption track, call the [captions.download](/youtube/v3/docs/captions/download) method. Set the [id](/youtube/v3/docs/captions/download#id) parameter value to the YouTube caption track ID that uniquely identifies the caption track that you are downloading. Your request must be authorized using OAuth 2.0.\n\nThe v3 API supports the following options:\n\n- To specify that a caption track should be returned in a specific format, set the [tfmt](/youtube/v3/docs/captions/download#tfmt) parameter value to identify the desired format. The parameter definition lists supported values.\n\n- To retrieve a translation of a caption track, set the [tlang](/youtube/v3/docs/captions/download#tlang) parameter value to an [ISO 639-1 two-letter language code](http://www.loc.gov/standards/iso639-2/php/code_list.php) that identifies the desired caption language. The translation is generated by using machine translation, such as Google Translate.\n\nSee the [captions.download](/youtube/v3/docs/captions/download#examples) method's documentation for code samples.\n\nUpdate a caption track\n----------------------\n\nThe API supports the ability to change a caption track's [draft status](/youtube/v3/docs/captions#snippet.isDraft), upload a new caption track for a file, or both.\n\nYou can use the APIs Explorer to test the ability to change a track's draft status. However, you cannot use the APIs Explorer to update the actual caption track because tool does not support the ability to upload files.\n\nThe request below retrieves a list of captions for a video on the Google Stories YouTube channel:\n\nThe request updates the draft status of a caption track to `true`, which means the track will not be publicly visible. To complete the request in the APIs Explorer, you need to set the `id` property's value to identify a caption track. \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.captions.update?\npart=snippet\n```\n\nSee the [captions.update](/youtube/v3/docs/captions/update#usage) method's documentation for code samples.\n\nDelete a caption track\n----------------------\n\nThis example shows how to delete a caption track. The example has the following steps:\n\n- **Step 1: Retrieve the caption track ID**\n\n Follow the steps above to [retrieve a list of caption tracks](#captions-list) for a video. The list could be used to display a list of caption tracks, using each track's ID as a key.\n- **Step 2: Delete the track**\n\n Call the [captions.delete](/youtube/v3/docs/captions/delete) method to delete a specific video. In the request, the `id` parameter specifies the caption track ID of the track that you are deleting. The request must be authorized using OAuth 2.0. If you are testing this query in the APIs Explorer, you will need to substitute a valid caption track ID for the `id` parameter value. \n\n ```\n https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.captions.delete?\n id=CAPTION_TRACK_ID\n ```"]]