I've built a small script that allow me to get keywords suggestion from Google search API.
The main problem is if the response contain special characters (like à é ù etc.) : my application return me unreadable keywords like that : �,�a,�a va,� majuscule,�a marche,�,�a y est,�a film,�gag,�a il est revenu,�a va de soi,,[object Object]
Here's my Node.js Script :
var express = require('express');
var request = require('request');
var app = express();
app.get('/sug', function (req, res) {
var KW = req.query.KW ;
console.time("Délai");
var url = "http://clients1.google.fr/complete/search?hl=fr&q=" + KW + "&json=t&client=hp";
request(url, function (err, resp, body) {
body = JSON.parse(body);
res.end(body.toString());
console.timeEnd("Délai");
});
});
app.listen(1337);
console.log('Serveur : OK');
The call is easy to make, just type http://localhost:1337/sug?KW=ç in your browser.
Do you know how to solve this and get the utf-8 working ?
["ç",["�","�a","� encoding","�in takvimi","�eyrek alt�n fiyat�","��plak k�zlar","�a��atay ulusoy","��plak kad�nlar","�ukurova �1\u20444niversitesi","�ocuk nas�l yap�l�r"],[],{"google:suggesttype":["QUERY","QUERY","QUERY","QUERY","QUERY","QUERY","QUERY","QUERY","QUERY","QUERY"]}]But after convert into UTF-8 we get that strange symbols ¿½,�aContent-TypeHTTP response header and is interpreting the encoding correctly.