filipedeschamps / video-maker

Projeto open source para fazer vídeos automatizados
MIT License
2.43k stars 629 forks source link

Problem com o google search #335

Closed thiagohenriquerossato closed 3 years ago

thiagohenriquerossato commented 3 years ago

Boa tarde pessoal. nao sei se ainda tem alguem que olhe isso aqui, mas aqui vai.

estou tendo um problema quando tento fazer a busca dos links das imagens geradas pelas keywords + search term fuçando bem aqui, descobri que esse erro ocorre com alguns termos. por exemplo: pesquisando 'Michael Jackson' const query = 'Michael Jackson' const imagesArray = await fetchGoogleAndReturnImagensLinks(query) console.dir(imagesArray, {depth: null}) os links vem normalmente, porem se pesquisar 'Michael Jackson singer', const query = 'Michael Jackson singer' const imagesArray = await fetchGoogleAndReturnImagensLinks(query) console.dir(imagesArray, {depth: null})

da um erro na hora de fazer o map e retirar os links. o retorno do google é um JSON diferente.

'Michael Jackson singer' { config: { url: 'https://customsearch.googleapis.com/customsearch/v1?cx=979f916544549e0 05&q=%22Michael%20Jackson%20singer%22&searchType=image&num=2&key=AIzaSyBjYkuiErx t4bplBXKdsU4lRSlDp8ZZFnY', method: 'GET', userAgentDirectives: [ { product: 'google-api-nodejs-client', version: '4.4.3', comment: 'gzip' } ], paramsSerializer: [Function (anonymous)], headers: { 'x-goog-api-client': 'gdcl/4.4.3 gl-node/14.15.4 auth/6.1.6', 'Accept-Encoding': 'gzip', 'User-Agent': 'google-api-nodejs-client/4.4.3 (gzip)', Accept: 'application/json' }, params: { cx: 'ID', q: '"Michael Jackson singer"', searchType: 'image', num: 2, key: 'apikey' }, validateStatus: [Function (anonymous)], retry: true, responseType: 'json' }, data: { kind: 'customsearch#search', url: { type: 'application/json', template: 'https://www.googleapis.com/customsearch/v1?q={searchTerms}&num= {count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&sort={sort?}&f ilter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTr anslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSea rchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={link Site?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict? }&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={ fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={ imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json' }, queries: { request: [ { title: 'Google Custom Search - "Michael Jackson singer"', searchTerms: '"Michael Jackson singer"', count: 2, startIndex: 1, inputEncoding: 'utf8', outputEncoding: 'utf8', safe: 'off', cx: '979f916544549e005', searchType: 'image' } ] }, searchInformation: { searchTime: 0.091499, formattedSearchTime: '0.09', totalResults: '0', formattedTotalResults: '0' } }, headers: { 'alt-svc': 'h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":44 3"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443" ; ma=2592000; v="46,43"', 'cache-control': 'private', connection: 'close', 'content-encoding': 'gzip', 'content-type': 'application/json; charset=UTF-8', date: 'Wed, 10 Feb 2021 20:17:29 GMT', server: 'ESF', 'transfer-encoding': 'chunked', vary: 'Origin, X-Origin, Referer', 'x-content-type-options': 'nosniff', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '0' }, status: 200, statusText: 'OK', request: { responseURL: 'https://customsearch.googleapis.com/customsearch/v1?cx=979f916 544549e005&q=%22Michael%20Jackson%20singer%22&searchType=image&num=2&key=AIzaSyB jYkuiErxt4bplBXKdsU4lRSlDp8ZZFnY' } } (node:2288) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'm ap' of undefined

thiagohenriquerossato commented 3 years ago

descobri. o problema ocorreu devido a configuração do CSE. resolvi fazendo outra CSE incluindo o *.google.com como site para busca. os resultados nao estao tao bons, mas é o que temos! caso ainda ocorra o problema, ha uma opção nas configuraçoes da CSE: Pesquisar em toda a web. a princípio ativei ela e resolveu o erro que estava dando, mas os resultados estavam vindo bem ruins, pouco ou nada a ver com search query.