YouTube 用户上传视频时如何调用函数? [英] How to call a function when a YouTube user uploads a video?

查看:24
本文介绍了YouTube 用户上传视频时如何调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个简单的聊天机器人,每当某个频道上传视频时,它都会发送一条消息,最好是视频的名称和视频的超链接.

YouTube 的 API 很奇怪,我完全不知道如何处理.

这是我目前所拥有的:

使用系统;使用 System.Linq;使用 Google.Apis.Services;使用 Google.Apis.YouTube.v3;YouTubeService 服务 = new YouTubeService(new BaseClientService.Initializer() {ApiKey = apiKey,应用名称 = "GoodApp"});var getChannel = service.Channels.List("snippet");getChannel.Id = channelId;var response = getChannel.Execute();var channel = response[0];//怎么办?

解决方案

使用 YouTube PubSubHubbub服务 您可以在频道上传新视频、更改视频标题或更改视频说明时收到推送通知.来自该页面的关于设置的引用:

<块引用>

  1. 设置可以处理传入 Atom 提要通知的回调服务器.
  2. 使用 Google 中心订阅接收推送通知:
    • 模式设置为订阅.(或将模式设置为 unsubscribe 以取消订阅.)
    • 回调 URL 设置为您在第 1 步中设置的 URL.
    • 主题网址设置为https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID,其中CHANNEL_ID 是您要检索推送的 YouTube 频道 ID通知.
  3. 处理发送到您的回调服务器的通知.[...]

不幸的是,回调服务器不仅仅是几行代码,这取决于您正在运行的服务器类型.如果您了解 PHP、AppEngine 或 Go,PubSubHubbub 上的订阅者存储库可能会有所帮助,否则搜索引擎似乎对我有好结果.

I'm trying to make a simple chatbot which will send a message whenever a certain channel uploads a video, ideally with the video's name and a hyperlink to the video.

YouTube's API is very strange, I haven't the slightest idea how to approach this.

This is what I have so far:

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?

解决方案

Using the YouTube PubSubHubbub service you can get push notifications when a channel uploads new videos, changes a video's title, or changes a video's description. Quote from that page about setting it up:

  1. Set up a callback server that can handle incoming Atom feed notifications.
  2. Use the Google hub to subscribe to receive push notifications:
    • Set the mode to subscribe. (Or set the mode to unsubscribe 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, where CHANNEL_ID is the YouTube channel ID for which you want to retrieve push notifications.
  3. Process notifications sent to your callback server. [...]

Unfortunately a callback server is more than a few lines of code, and it depends on what kind of server you're running. If you know PHP, AppEngine, or Go, the subscriber repositories on PubSubHubbub may be helpful, otherwise search engines seem to have good results for me.

这篇关于YouTube 用户上传视频时如何调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆