$. getJSON Google Images displaying incorrect results

Asked

Viewed 59 times

1

Based on this code:

function baixarCapa(capa, item) {
   $.getJSON("https://ajax.googleapis.com/ajax/services/search/images?callback=?", {
       q: '"' + capa + '"',
       v: '1.0'
   }, function(data) {
        var url = data.responseData.results[0].url;
        $('[data-capa=' + item + ']').html('<img src="' + url + '">');
    });
}

I can download artist images using the Google Images API, but the results are wrong in 50% of cases and are different from when I access the Google site and search by the same term.

Behaviour of $.getJSON http://img.somdomato.com/imagens/top10.jpg

Why does this happen? How can I correct this behavior? Thank you.

  • When YOU search, there is caching in your browser or even you are logged in to your google account, where there are preference mechanisms that will know for sure what you want. Try opening an anonymous tab and doing the search.

  • Yes, even with the anonymous tab the first result is completely different, and correct.

  • 1

    Just a question, how are you passing the value pro parameter capa?

  • You nailed it, I was seeking Artist - Music when the correct was only Artist!

1 answer

1


I was looking for artist and music when the right thing would be just the artist. I altered:

capa = nome.split('/').pop();

To:

capa = nome.split('/').pop().split('-');

And use capa[0] instead of capa.

Thank you for your attention! In particular to @rrnan

Browser other questions tagged

You are not signed in. Login or sign up in order to post.