Foros del Web » Programando para Internet » Javascript »

Buscar imagenes en google

Estas en el tema de Buscar imagenes en google en el foro de Javascript en Foros del Web. Hola gente, cómo andan tanto tiempo? Vuelvo con un problemita con este código que saque de Google Code - Code Playground. Quiero poner en mi ...
  #1 (permalink)  
Antiguo 19/05/2014, 18:35
 
Fecha de Ingreso: septiembre-2008
Mensajes: 66
Antigüedad: 15 años, 7 meses
Puntos: 0
Buscar imagenes en google

Hola gente, cómo andan tanto tiempo? Vuelvo con un problemita con este código que saque de Google Code - Code Playground. Quiero poner en mi página una imagen dada una búsqueda en google imagenes que se realiza mediante este javascript:

/*
* How to search for images and restrict them by size.
* This demo will also show how to use Raw Searchers, aka a searcher that is
* not attached to a SearchControl. Thus, we will handle and draw the results
* manually.
*/

google.load('search', '1');

function searchComplete(searcher) {
alert(searcher);
// Check that we got results
if (searcher.results && searcher.results.length > 0) {
// Grab our content div, clear it.
var contentDiv = document.getElementById('content2');
contentDiv.innerHTML = '';

// Loop through our results, printing them to the page.
var results = searcher.results;
//for (var i = 0; i < results.length; i++) {
for (var i = 0; i < 1; i++) {
// For each result write it's title and image to the screen
var result = results[i];
var imgContainer = document.createElement('div');

var title = document.createElement('h2');
// We use titleNoFormatting so that no HTML tags are left in the title
title.innerHTML = result.titleNoFormatting;

var newImg = document.createElement('img');
// There is also a result.url property which has the escaped version
newImg.src = result.tbUrl;

//imgContainer.appendChild(title);
imgContainer.appendChild(newImg);

// Put our title + image in the content
contentDiv.appendChild(imgContainer);
}
}
}

function OnLoad() {
// Our ImageSearch instance.
var imageSearch = new google.search.ImageSearch();

// Restrict to extra large images only
imageSearch.setRestriction(google.search.ImageSear ch.RESTRICT_IMAGESIZE,
google.search.ImageSearch.IMAGESIZE_MEDIUM);

// Here we set a callback so that anytime a search is executed, it will call
// the searchComplete function and pass it our ImageSearch searcher.
// When a search completes, our ImageSearch object is automatically
// populated with the results.
imageSearch.setSearchCompleteCallback(this, searchComplete, [imageSearch]);


// Find me a beautiful car.
imageSearch.execute("metallica");
}
google.setOnLoadCallback(OnLoad);


-------------------------------------------------------------------------------------------------
Hasta funciona el código, me trae la primer imagen del resultado "metallica" y me lo muestra en el div con id "content2". Pero lo que quiero hacer es que metallica sea pasado mediante una variable en php. Cómo puedo hacer esto? Intenté poner imageSearch.execute(<?php echo $variable; ?>); pero no funciona. No entiendo bien cómo funciona todo esto. Ayuda please :)
  #2 (permalink)  
Antiguo 19/05/2014, 18:47
Avatar de Italico76  
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 1 mes
Puntos: 292
Respuesta: Buscar imagenes en google

Deberias hacer un UPLOAD de la imagen mediante un form aunque no es necesario mostrarle al usuario ningun elemento del mismo

Lo envias obviamente por POST
__________________
Salu2!
  #3 (permalink)  
Antiguo 19/05/2014, 18:49
 
Fecha de Ingreso: septiembre-2008
Mensajes: 66
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Buscar imagenes en google

No entiendo lo que me decis :/ podrías poner algo de código?
  #4 (permalink)  
Antiguo 19/05/2014, 19:07
 
Fecha de Ingreso: septiembre-2008
Mensajes: 66
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: Buscar imagenes en google

O qué me recomiendan hacer? Yo quiero a partir de un montón de nombres traer o guardar sus imagenes que aparecen en google imagenes. Está bien lo que quiero hacer? O no se puede o no se debe?

Etiquetas: funcion, google, html, imagenes, php, variable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:36.