我正在使用以下代码来获取嵌入在我的asp.net应用程序中的youtube视频的标题和描述。我可以看到标题,但看不到描述。
我使用Atomfeed执行此操作...
问题是我为我所有的视频获取的描述都为“Google.GData.Client.AtomTextConstruct” 。
Private Function GetTitle(ByVal myFeed As AtomFeed) As String
Dim strTitle As String = ""
For Each entry As AtomEntry In myFeed.Entries
strTitle = entry.Title.Text
Next
Return strTitle
End Function
Private Function GetDesc(ByVal myFeed As AtomFeed) As String
Dim strDesc As String = ""
For Each entry As AtomEntry In myFeed.Entries
strDesc = entry.Summary.ToString()
Next
Return strDesc
End Function
最佳答案
我相信,当解析来自原子供稿的XML时,不会处理该描述。看看这个:http://code.google.com/p/google-gdata/wiki/UnderstandingTheUnknown
But what happens with things that are not understood? They end up as an element of the ExtensionElements collection, that is a member of all classes inherited from AtomBase, like AtomFeed, AtomEntry, EventEntry etc...
因此,我们可以做的是像这样从扩展元素中提取描述:
Dim query As New FeedQuery()
Dim service As New Service()
query.Uri = New Uri("https://gdata.youtube.com/feeds/api/standardfeeds/top_rated")
Dim myFeed As AtomFeed = service.Query(query)
For Each entry In myFeed.Entries
For Each obj As Object In entry.ExtensionElements
If TypeOf obj Is XmlExtension Then
Dim xel As XElement = XElement.Parse(TryCast(obj, XmlExtension).Node.OuterXml)
If xel.Name = "{http://search.yahoo.com/mrss/}group" Then
Dim descNode = xel.Descendants("{http://search.yahoo.com/mrss/}description").FirstOrDefault()
If descNode IsNot Nothing Then
Console.WriteLine(descNode.Value)
End If
Exit For
End If
End If
Next
Next
另外,获取“Google.GData.Client.AtomTextConstruct”的原因是因为Summary是Google.GData.Client.AtomTextConstruct类型的对象,因此执行entry.Summary.ToString()只是为您提供默认的ToString( )的行为。您通常会执行Summary.Text,但这当然是空白的,因为如上所述,库没有正确处理它。
关于asp.net - 如何在asp.net应用程序中获取Youtube嵌入式视频的描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12255999/