0

我正在尝试做一个 Bing 图像搜索应用程序(Azure 版本),但我无法取得进展。代码语言是 vb.net。基本上我正在做的是尝试编辑这段代码,它确实有效。任何解决方案?

Function ExecuteQuery() As Boolean
    Dim esito As Boolean = False
    Try
        Dim query As String = System.Web.HttpUtility.UrlEncode("Inception Movie")
        Dim skip As String = "10"
        Dim urlBase As New Uri("https://api.datamarket.azure.com")

        Dim accountKey As String = "tymv8z6jFSdo4eQ3vsS5r8SZAmFtA24e6dmfyvaLh3U"
        Dim credentials As New NetworkCredential(accountKey, accountKey)

        Dim dsc As New System.Data.Services.Client.DataServiceContext(urlBase)

        dsc.Credentials = New NetworkCredential(accountKey, accountKey)

        Dim urlSearch As Uri = New Uri(("https://api.datamarket.azure.com/Bing/Search/Image?Query=%27" + query + "%27&$skip=" + skip))
        Dim webResults = dsc.Execute(Of WebResult)(urlSearch)
        For Each result As WebResult In webResults
            ListBox1.Items.Add(result.Title)
            ListBox1.Items.Add(result.Description)
            singleValue = singleValue + 1
        Next

        esito = True
    Catch ex As Exception
        esito = False
    End Try

    Return esito
End Function

Partial Public Class WebResult
    Private _ID As Guid
    Private _Title As [String]
    Private _Description As [String]
    Private _DisplayUrl As [String]
    Private _Url As [String]
    Private _MediaUrl As [String]

    Public Property ID() As Guid
        Get
            Return Me._ID
        End Get
        Set(ByVal value As Guid)
            Me._ID = value
        End Set
    End Property

    Public Property Title() As [String]
        Get
            Return Me._Title
        End Get
        Set(ByVal value As [String])
            Me._Title = value
        End Set
    End Property

    Public Property Description() As [String]
        Get
            Return Me._Description
        End Get
        Set(ByVal value As [String])
            Me._Description = value
        End Set
    End Property

    Public Property DisplayUrl() As [String]
        Get
            Return Me._DisplayUrl
        End Get
        Set(ByVal value As [String])
            Me._DisplayUrl = value
        End Set
    End Property

    Public Property Url() As [String]
        Get
            Return Me._Url
        End Get
        Set(ByVal value As [String])
            Me._Url = value
        End Set
    End Property
    Public Property MediaUrl() As [String]
        Get
            Return Me._MediaUrl
        End Get
        Set(ByVal value As [String])
            Me._MediaUrl = value
        End Set
    End Property
End Class
4

1 回答 1

0

我现在解决了这个难题,建立了一个简单的方法来做这件事,只使用一个类文件:

1 - 只需下载此文件:http ://www.getcodesamples.com/src/15958EA3/F43E1E1A 2 - 然后将相同的文件添加到您的项目 3 - 添加以下代码:

Dim strBingKey As String = "xxxaccountkeyxxx"
    Dim bingClass As New Bing.BingSearchContainer(New Uri("https://api.datamarket.azure.com/Bing/Search/"))
    bingClass.Credentials = New NetworkCredential(strBingKey, strBingKey)

    Dim query = bingClass.Image("Inception" + "Movie", Nothing, "en-us", "Off", Nothing, Nothing, Nothing)
    Dim results = query.Execute()
    For Each result In results
        ListBox1.Items.Add(result.Title)
        ListBox1.Items.Add(result.MediaUrl)
        Console.WriteLine(result.Thumbnail) 'ThumbNail type, need to convert to use in result list

    Next

谢谢大家的耐心等待!

于 2013-11-12T18:32:24.913 回答