Youtube .net api - 在播放列表中搜索
当我尝试在 Google 播放列表中搜索时,出现 403(禁止)错误。如果我删除 .Query 它工作正常。我知道这些凭据工作正常,因为我在应用程序的其他地方使用它们没有问题。
我是否以错误的方式处理这个问题,或者这是不可能的?我正在使用 1.8.0.0 版本的 api(新下载)。
void SearchPlaylistVideos(string playListId, string query)
{
YouTubeQuery videoQuery = new YouTubeQuery(String.Format("http://gdata.youtube.com/feeds/api/playlists/{0}", playListId));
videoQuery.Query = query;
Feed<Video> feed = CreateAuthenticatedRequest().Get<Video>(videoQuery);
foreach (Video entry in feed.Entries) {
//Response.Write("<br />" + entry.Title);
}
}
YouTubeRequest CreateAuthenticatedRequest()
{
YouTubeRequestSettings settings = new YouTubeRequestSettings
(
ConfigurationManager.AppSettings["GData.AppName"],
ConfigurationManager.AppSettings["GData.DeveloperKey"],
ConfigurationManager.AppSettings["GData.Email"],
ConfigurationManager.AppSettings["GData.Password"]
);
settings.Timeout = 1000000;
return new YouTubeRequest(settings);
}
I'm getting a 403 (forbidden) error when I try to search inside a google playlist. If I remove the .Query it works fine. I know the credentials work fine as I'm using them in other places in the application without a problem.
Am I going about this this wrong way, or is this not possible? I'm using version 1.8.0.0 of the api (new download).
void SearchPlaylistVideos(string playListId, string query)
{
YouTubeQuery videoQuery = new YouTubeQuery(String.Format("http://gdata.youtube.com/feeds/api/playlists/{0}", playListId));
videoQuery.Query = query;
Feed<Video> feed = CreateAuthenticatedRequest().Get<Video>(videoQuery);
foreach (Video entry in feed.Entries) {
//Response.Write("<br />" + entry.Title);
}
}
YouTubeRequest CreateAuthenticatedRequest()
{
YouTubeRequestSettings settings = new YouTubeRequestSettings
(
ConfigurationManager.AppSettings["GData.AppName"],
ConfigurationManager.AppSettings["GData.DeveloperKey"],
ConfigurationManager.AppSettings["GData.Email"],
ConfigurationManager.AppSettings["GData.Password"]
);
settings.Timeout = 1000000;
return new YouTubeRequest(settings);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们曾经处理过一个有些类似的问题:我们的客户在“应用程序”中输入 YouTube 查询词,返回整个查询的结果,然后客户选择视频保存到应用程序的数据库中。然后,我们可以让应用程序将自定义播放列表发送到客户端的站点。然后,该网站的访问者可以使用搜索词搜索视频。我们使用 Lucene.net 在这些自定义“应用程序”列表上运行查询。根据您的情况,您可以:
这肯定会占用更多资源(存储、周期),并且您可能需要加快使用 Lucene 的 API,但我同意 Данаил 的观点,即快速简便的方法(YouTube 允许对播放列表进行自定义查询)行不通。
We've worked on a somewhat similar problem: Our client enters a YouTube query term into "The App", results for the entire query are returned, and then the client picks videos to persist to the App's db. We can then have the app spit out a custom playlist to the client's site. Visitors to this site can then search for videos with a search term. We use Lucene.net to run queries on these custom "App" lists. With your situation, could you:
It's definitely more resource (storage, cycles) intensive, and you may need to get up to speed with Lucene's API, but I concur with Данаил that the quick and easy way (YouTube allowing custom queries on playlists) won't work.
刚刚嗅探了代码正在发出的 HTTP 请求 - 你得到了错误 403,因为
这听起来像 YouTube API 不支持特定播放列表中的全文搜索。实际上,
YouTubeQuery.Query
方法只是向您的基本 URI 添加一个字符串,如下所示(您可以查看 FeedQuery 和 YouTubeQuery 类源代码):因此,使用
.Query,您的最终网址是这样的(如果
query = "life"
):http://gdata.youtube.com/feeds/api/playlists/595A40209CB17411?q =生活
Just sniffed the HTTP request that the code is making - you got Error 403, because
This sounds like the YouTube API doesn't support full text search in specific playlist. Actually the
YouTubeQuery.Query
method just adds a string to your base URI, something like this (you can take a look at the FeedQuery and YouTubeQuery classes source):So, with
.Query
, your final url is this (ifquery = "life"
):http://gdata.youtube.com/feeds/api/playlists/595A40209CB17411?q=life