gpt4 book ai didi

c# - YouTube Feed解析XML C# Razor

转载 作者:行者123 更新时间:2023-12-03 05:33:31 24 4
gpt4 key购买 nike

我正在尝试解析youtube xml提要,并循环浏览某个用户的视频,您该怎么做?我正在使用umbraco Razor (C#)。

@using System;
@using System.Linq;
@using System.Collections.Generic;
@using System.Xml;
@using umbraco.MacroEngines;
@using System.Xml.Linq;
@inherits System.Xml.XPath.XPathNodeIterator;
@inherits umbraco.MacroEngines.DynamicNodeContext;
@inherits DynamicNodeContext

@{
dynamic xmlv = new DynamicXml(umbraco.library.GetXmlDocumentByUrl("https://gdata.youtube.com/feeds/api/users/[username]/uploads"));

<ul>
@foreach (var property in xmlv.BaseElement.Elements.Where(x => x.Elements("Name") == "group"))
{
<li>
<p>
@property.Title
@property.Content
@property.Thumbnail
</p>
</li>
}
</ul>
}

最佳答案

XDocument xDoc = XDocument.Load("https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed");
XNamespace media = "http://search.yahoo.com/mrss/";
XNamespace yt = "http://gdata.youtube.com/schemas/2007";

var items = xDoc.Descendants(media + "group")
.Select(i => new
{
Title = i.Element(media + "title").Value,
Content = i.Element(media + "content").Attribute("url").Value,
Thumbnail = i.Element(media + "thumbnail").Attribute("url").Value,
Uploaded = (DateTime)i.Element(yt + "uploaded"),
})
.ToList();

关于c# - YouTube Feed解析XML C# Razor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13141251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com