我正在尝试制作一个简单的聊天机器人,它会在某个 channel 上传视频时发送一条消息,最好是包含视频的名称和视频的超链接。
YouTube 的 API 很奇怪,我完全不知道如何处理。
这是我目前所拥有的:
using System;
using System.Linq;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
YouTubeService service = new YouTubeService(new BaseClientService.Initializer() {
ApiKey = apiKey,
ApplicationName = "GoodApp"
});
var getChannel = service.Channels.List("snippet");
getChannel.Id = channelId;
var response = getChannel.Execute();
var channel = response[0]; //now what?
最佳答案
使用 the YouTube PubSubHubbub service当 channel 上传新视频、更改视频标题或更改视频描述时,您可以收到推送通知。从该页面引用有关设置的信息:
- Set up a callback server that can handle incoming Atom feed notifications.
- Use the Google hub to subscribe to receive push notifications:
- Set the mode to
subscribe
. (Or set the mode tounsubscribe
to cancel a subscription.)- Set the callback URL to the URL that you set up in step 1.
- Set the topic URL to
https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID
, whereCHANNEL_ID
is the YouTube channel ID for which you want to retrieve push notifications.- Process notifications sent to your callback server. [...]
不幸的是,回调服务器不仅仅是几行代码,而且这取决于您运行的服务器类型。如果您了解 PHP、AppEngine 或 Go,订阅者存储库位于 PubSubHubbub可能会有帮助,否则搜索引擎似乎对我有很好的结果。
关于c# - 如何在 YouTube 用户上传视频时调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37913009/