Pergunta

I'm trying to do a Bing Image Search Application (Azure Version), and i can't make progress. The code language is vb.net. Basically what i'm doing is trying to edit this code, that actually worked. Any Solutions ?

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
Foi útil?

Solução

I now solved the puzzle, founded a simple way to do this thing just using an class file:

1 - Just download this file: http://www.getcodesamples.com/src/15958EA3/F43E1E1A 2 - Then add the same file to your project 3 - Add the following code:

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

Thank you all for the patience!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top