Chúng tôi đang cập nhật Data API để phù hợp với cách YouTube tính số lượt xem video ngắn.
Tìm hiểu thêm
Mẫu mã API dữ liệu YouTube (v3)
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bạn có thể khám phá các trường hợp sử dụng phổ biến của API Dữ liệu YouTube và API Phát trực tiếp trên YouTube trên trang trường hợp sử dụng và mã mẫu.
Trang này cho phép bạn chọn một tài nguyên và phương thức API, sau đó liệt kê các trường hợp sử dụng phổ biến cho phương thức đó. Sau đó, bạn có thể nhấp vào bất kỳ trường hợp sử dụng nào để điền thông số mẫu và giá trị thuộc tính cho trường hợp sử dụng đó vào tiện ích Trình khám phá API. Bạn cũng có thể mở tiện ích Trình khám phá API ở chế độ toàn màn hình để xem các mã mẫu đang hoạt động cho Java, JavaScript, PHP và Python. Nếu bạn cập nhật giá trị tham số hoặc thuộc tính trong Trình khám phá API, thì các mẫu mã cũng sẽ cập nhật để phản ánh các thay đổi của bạn.
Phần sau đây liệt kê các mã mẫu có sẵn bằng các ngôn ngữ khác.
Đoạn mã độc lập
Các danh sách dưới đây xác định các mã mẫu có sẵn cho YouTube Data API (phiên bản 3) bằng các ngôn ngữ khác ngoài Java, JavaScript, PHP và Python. Như đã lưu ý trong phần trước, bạn có thể xem các mã mẫu cho những ngôn ngữ đó trên trang trường hợp sử dụng và mã mẫu.
Ruby
Bạn cũng có thể điều chỉnh một trong các mẫu Ruby khác.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-21 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-21 UTC."],[[["\u003cp\u003eExplore the use cases and code samples page to find examples for the YouTube Data API and YouTube Live Streaming API.\u003c/p\u003e\n"],["\u003cp\u003eThe use cases and code samples page provides interactive samples in Java, JavaScript, PHP, and Python, allowing you to adjust parameters and see updated code.\u003c/p\u003e\n"],["\u003cp\u003eStandalone code snippets are available for Apps Script, Go, .NET, and Ruby, demonstrating common methods like uploading videos, searching for videos, and managing playlists.\u003c/p\u003e\n"],["\u003cp\u003eThe page provides code samples for several common methods including subscriptions.insert, channels.list, search.list, and videos.update, allowing developers to find quick snippets for their use cases.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided for various common tasks such as authorization, uploading, and searching for videos, as well as creating playlists and subscriptions.\u003c/p\u003e\n"]]],["The document details code samples for the YouTube Data API and YouTube Live Streaming API. Users can find examples for common use cases by selecting an API resource and method. The APIs Explorer widget allows interaction with samples, including parameter adjustments, with working code in Java, JavaScript, PHP, and Python. Additional code snippets are available in Apps Script, Go, .NET, and Ruby, covering actions like subscribing to channels, retrieving uploads, searching videos, updating videos, and creating playlists.\n"],null,["# YouTube Data API (v3) Code Samples\n\nYou can explore common use cases for the YouTube Data API and YouTube Live Streaming API on the [use cases and code samples](/youtube/v3/code_samples/code_snippets) page.\n\nThe page lets you select an API resource and method and then lists common use cases for that method. You can then click on any use case to populate the APIs Explorer widget with sample parameter and property values for that use case. You can also open the fullscreen APIs Explorer widget to see working code samples for Java, JavaScript, PHP, and Python. If you update parameter or property values in the APIs Explorer, the code samples also update to reflect your changes.\n\nThe following section lists code samples available in other languages.\n\nStandalone code snippets\n------------------------\n\nThe lists below identify code samples available for the YouTube Data API (v3) in languages other than Java, JavaScript, PHP, and Python. As noted in the previous section, code samples for those languages are available on the [use cases and code samples](/youtube/v3/code_samples/code_snippets) page. \n\n### Apps Script\n\n| Code sample | Methods |\n|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------|\n| [Add a channel subscription](/youtube/v3/code_samples/apps-script#subscribe_to_channel) | [subscriptions.insert](/youtube/v3/docs/subscriptions/insert) |\n| [Retrieve current user's uploads](/youtube/v3/code_samples/apps-script#retrieve_my_uploads) | [channels.list](/youtube/v3/docs/channels/list) |\n| [Search for videos related to a keyword](/youtube/v3/code_samples/apps-script#search_by_keyword) | [search.list](/youtube/v3/docs/search/list) |\n| [Update a video](/youtube/v3/code_samples/apps-script#update_video) | [videos.update](/youtube/v3/docs/videos/update) |\n\n### Go\n\n| Code sample | Methods |\n|-----------------------------------------------------------------------------------------|-----------------------------------------------------------|\n| [Authorize a request](/youtube/v3/code_samples/go#authorize_a_request) | Any method requiring authorization |\n| [Retrieve current user's uploads](/youtube/v3/code_samples/go#retrieve_my_uploads) | [playlistItems.list](/youtube/v3/docs/playlistItems/list) |\n| [Search for videos related to a keyword](/youtube/v3/code_samples/go#search_by_keyword) | [search.list](/youtube/v3/docs/search/list) |\n| [Upload a video](/youtube/v3/code_samples/go#upload_a_video) | [videos.insert](/youtube/v3/docs/videos/insert) |\n\n### .NET\n\n| Code sample | Methods |\n|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|\n| [Create a playlist](/youtube/v3/code_samples/dotnet#create_a_playlist) | [playlists.insert](/youtube/v3/docs/playlists/insert) |\n| [Retrieve current user's uploaded videos](/youtube/v3/code_samples/dotnet#retrieve_my_uploads) | [channels.list](/youtube/v3/docs/channels/list) [playlistItems.list](/youtube/v3/docs/playlistItems/list) |\n| [Search for videos related to a keyword](/youtube/v3/code_samples/dotnet#search_by_keyword) | [search.list](/youtube/v3/docs/search/list) |\n| [Upload a video](/youtube/v3/code_samples/dotnet#upload_a_video) | [videos.insert](/youtube/v3/docs/videos/insert) |\n\n### Ruby\n\n| Code sample | Methods |\n|-------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|\n| [Authorize a request](/youtube/v3/code_samples/ruby#authorize_a_request) | Any method requiring authorization |\n| [Create a channel subscription](/youtube/v3/code_samples/ruby#add_a_channel_subscription) | [subscriptions.insert](/youtube/v3/docs/subscriptions/insert) |\n| [Retrieve current user's uploads](/youtube/v3/code_samples/ruby#retrieve_my_uploads) | [channels.list](/youtube/v3/docs/channels/list) [playlistItems.list](/youtube/v3/docs/playlistItems/list) |\n| [Search for videos related to a keyword](/youtube/v3/code_samples/ruby#search_by_keyword) | [search.list](/youtube/v3/docs/search/list) |\n| [Upload a video](/youtube/v3/code_samples/ruby#upload_a_video) | [videos.insert](/youtube/v3/docs/videos/insert) |\n\nYou may also be able to adapt one of the other\n[Ruby samples](https://github.com/googleapis/google-api-ruby-client/tree/main/samples)."]]