เรากำลังอัปเดต Data API ให้สอดคล้องกับวิธีที่ YouTube นับยอดดูสำหรับ Shorts
ดูข้อมูลเพิ่มเติม
สมัครรับข้อมูลข้อความ Push
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
YouTube Data API (v3) สนับสนุนข้อความ Push ผ่าน PubSubHubbub ซึ่งเป็นโปรโตคอลการเผยแพร่/สมัครรับข้อมูลแบบเซิร์ฟเวอร์ต่อเซิร์ฟเวอร์สำหรับทรัพยากรที่เข้าถึงได้ทางเว็บ ระบบจะส่งการแจ้งเตือนไปยังผู้สมัครใช้บริการผ่านเว็บฮุค HTTP ซึ่งมีประสิทธิภาพมากกว่าโซลูชันที่ใช้แบบสำรวจ การใช้ PubSubHubbub จะทำให้เซิร์ฟเวอร์ของคุณทราบเหตุการณ์ต่างๆ ได้แบบเกือบเรียลไทม์โดยไม่ต้องกำหนดช่วงการหยั่งสัญญาณที่เหมาะสมที่สุดหรือดึงข้อมูลซ้ำๆ ที่ไม่มีการเปลี่ยนแปลง
เซิร์ฟเวอร์เรียกกลับของ PubSubHubbub จะได้รับการแจ้งเตือนฟีด Atom เมื่อช่องดำเนินการใดๆ ต่อไปนี้
- อัปโหลดวิดีโอ
- อัปเดตชื่อของวิดีโอ
- อัปเดตคำอธิบายวิดีโอ
ขั้นตอนต่อไปนี้อธิบายวิธีสมัครรับการแจ้งเตือน
-
ตั้งค่าเซิร์ฟเวอร์โค้ดเรียกกลับที่จัดการการแจ้งเตือนฟีด Atom ขาเข้าได้
-
ใช้ Google เพื่อสมัครรับข้อมูลเพื่อรับข้อความ Push:
-
ตั้งค่า mode เป็น subscribe
(หรือตั้งค่าโหมดเป็น unsubscribe
เพื่อยกเลิกการสมัครใช้บริการ)
-
ตั้งค่า URL เรียกกลับเป็น URL ที่คุณตั้งค่าไว้ในขั้นตอนที่ 1
-
ตั้งค่า URL หัวข้อเป็น https://www.youtube.com/feeds/videos.xml?channel_id=CHANNEL_ID
โดยที่ CHANNEL_ID
คือรหัสช่อง YouTube ที่คุณต้องการใช้เรียกข้อความ Push
-
ประมวลผลการแจ้งเตือนที่ส่งไปยังเซิร์ฟเวอร์เรียกกลับ รูปแบบการแจ้งเตือนจะแสดงอยู่ด้านล่างนี้ โปรดทราบว่าคุณใช้ค่าขององค์ประกอบ <yt:videoId>
เพื่อระบุวิดีโอที่เพิ่มเข้ามาหรืออัปเดตใหม่ได้ นอกจากนี้ คุณยังใช้ค่าขององค์ประกอบ <yt:channelId>
เพื่อระบุช่องที่เป็นเจ้าของวิดีโอดังกล่าวได้ด้วย
<feed xmlns:yt="http://www.youtube.com/xml/schemas/2015"
xmlns="http://www.w3.org/2005/Atom">
<link rel="hub" href="https://pubsubhubbub.appspot.com"/>
<link rel="self" href="https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID"/>
<title>YouTube video feed</title>
<updated>2015-04-01T19:05:24.552394234+00:00</updated>
<entry>
<id>yt:video:VIDEO_ID</id>
<yt:videoId>VIDEO_ID</yt:videoId>
<yt:channelId>CHANNEL_ID</yt:channelId>
<title>Video title</title>
<link rel="alternate" href="http://www.youtube.com/watch?v=VIDEO_ID"/>
<author>
<name>Channel title</name>
<uri>http://www.youtube.com/channel/CHANNEL_ID</uri>
</author>
<published>2015-03-06T21:40:57+00:00</published>
<updated>2015-03-09T19:05:24.552394234+00:00</updated>
</entry>
</feed>
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2023-10-26 UTC
[null,null,["อัปเดตล่าสุด 2023-10-26 UTC"],[[["\u003cp\u003eThe YouTube Data API v3 uses PubSubHubbub for push notifications, enabling near real-time updates without the need for constant polling.\u003c/p\u003e\n"],["\u003cp\u003eYour server will receive notifications when a YouTube channel uploads a video or updates a video's title or description.\u003c/p\u003e\n"],["\u003cp\u003eTo subscribe, set up a callback server, use the Google hub with the 'subscribe' mode, provide your callback URL, and specify the YouTube channel ID in the topic URL.\u003c/p\u003e\n"],["\u003cp\u003eNotifications are sent as Atom feeds, and the \u003ccode\u003e<yt:videoId>\u003c/code\u003e and \u003ccode\u003e<yt:channelId>\u003c/code\u003e elements within these feeds can be used to identify the specific video and channel.\u003c/p\u003e\n"]]],["The YouTube Data API uses PubSubHubbub for push notifications, sending Atom feed updates to subscribers' HTTP webhooks when a channel uploads a video, or updates a video's title or description. To subscribe, set up a callback server, then use the Google hub with `subscribe` mode, your server's callback URL, and a YouTube channel's ID-specific topic URL. Notifications, sent as Atom feeds, include the video and channel IDs, as well as video titles and other information.\n"],null,["# Subscribe to Push Notifications\n\nThe YouTube Data API (v3) supports push notifications via [PubSubHubbub](https://github.com/pubsubhubbub/), a server-to-server publish/subscribe protocol for Web-accessible resources. Notifications are pushed out to subscribers via HTTP webhooks, which is much more efficient than polling-based solutions. With PubSubHubbub, your server finds out about events in near real-time, without having to determine the optimal polling interval or repeatedly fetching data that hasn't changed.\n\nYour PubSubHubbub callback server receives Atom feed notifications when a channel does any of the following activities:\n\n\u003cbr /\u003e\n\n- uploads a video\n- updates a video's title\n- updates a video's description\n\n\u003cbr /\u003e\n\nThe following steps explain how to subscribe to notifications:\n\n1. Set up a callback server that can handle incoming Atom feed notifications.\n\n2. Use the [Google](https://pubsubhubbub.appspot.com/subscribe) hub to subscribe to receive push notifications:\n\n - Set the **mode** to `subscribe`. (Or set the mode to `unsubscribe` to cancel a subscription.)\n\n - Set the **callback URL** to the URL that you set up in step 1.\n\n - Set the **topic URL** to `https://www.youtube.com/feeds/videos.xml?channel_id=`**CHANNEL_ID**, where **CHANNEL_ID** is the [YouTube channel ID](/youtube/v3/docs/channels#id) for which you want to retrieve push notifications.\n\n3. Process notifications sent to your callback server. The notification format is shown below. Note that you can use the `\u003cyt:videoId\u003e` element's value to identify the newly added or updated video. You can also use the `\u003cyt:channelId\u003e` element's value to identify the channel that owns that video.\n\n ```\n \u003cfeed xmlns:yt=\"http://www.youtube.com/xml/schemas/2015\"\n xmlns=\"http://www.w3.org/2005/Atom\"\u003e\n \u003clink rel=\"hub\" href=\"https://pubsubhubbub.appspot.com\"/\u003e\n \u003clink rel=\"self\" href=\"https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID\"/\u003e\n \u003ctitle\u003eYouTube video feed\u003c/title\u003e\n \u003cupdated\u003e2015-04-01T19:05:24.552394234+00:00\u003c/updated\u003e\n \u003centry\u003e\n \u003cid\u003eyt:video:VIDEO_ID\u003c/id\u003e\n \u003cyt:videoId\u003eVIDEO_ID\u003c/yt:videoId\u003e\n \u003cyt:channelId\u003eCHANNEL_ID\u003c/yt:channelId\u003e\n \u003ctitle\u003eVideo title\u003c/title\u003e\n \u003clink rel=\"alternate\" href=\"http://www.youtube.com/watch?v=VIDEO_ID\"/\u003e\n \u003cauthor\u003e\n \u003cname\u003eChannel title\u003c/name\u003e\n \u003curi\u003ehttp://www.youtube.com/channel/CHANNEL_ID\u003c/uri\u003e\n \u003c/author\u003e\n \u003cpublished\u003e2015-03-06T21:40:57+00:00\u003c/published\u003e\n \u003cupdated\u003e2015-03-09T19:05:24.552394234+00:00\u003c/updated\u003e\n \u003c/entry\u003e\n \u003c/feed\u003e\n ```"]]