2

我正在使用下面的代码来获取嵌入在我的 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
4

2 回答 2

1

我相信,当解析来自 atom 提要的 XML 时,不会处理描述。看看这个:http ://code.google.com/p/google-gdata/wiki/UnderstandingTheUnknown

但是不理解的事情会发生什么?它们最终成为 ExtensionElements 集合的一个元素,它是从 AtomBase 继承的所有类的成员,如 AtomFeed、AtomEntry、EventEntry 等......

所以,我们可以做的是从扩展元素中提取描述,如下所示:

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,但这当然是空白的,因为正如我上面所说,库没有正确处理它。

于 2012-09-06T06:27:49.450 回答
0

对于 youtube,我使用 Google.GData.YouTube 获取每个视频的信息。

像这样的东西会从视频中返回很多信息。

Dim yv As Google.YouTube.Video

url = New Uri("http://gdata.youtube.com/feeds/api/videos/" & video.Custom)

r = New YouTubeRequest(New YouTubeRequestSettings("??", "??"))
yv = r.Retrieve(Of Video)(url)

然后可以通过以下方式获取描述:yv.Description

于 2012-09-07T23:24:42.780 回答