404 error on Translate API call

208 views
Skip to first unread message

Brian Grant

unread,
Jul 19, 2012, 8:00:26 AM7/19/12
to google-api-jav...@googlegroups.com
Hi folks,

I may be doing something really stupid here, but can't for the life of me figure out why I keep getting a 404 / Not Found response when calling the language.translations.list service of the Translate API.  Any tips would be appreciated.  Here is the relevant code:

 function translateButtonClick() {
gapi.client.load('translate', 'v2', function() {
var request = gapi.client.language.translations.list({
 'q': document.getElementById('source').value,
 'source': 'en',
 'target': 'fr'
});
request.execute(function(response) {
console.log(request);
console.log(response);
var results = document.getElementById('results');
results.innerHTML = response.data.translations[0].translatedText;
});
});
 }

I can see in the console that the script is successfully getting into the execute callback, but the response has a 404 error and the script actually fails because response.data.translations is undefined.

Thanks,
Brian

Brian Grant

unread,
Jul 20, 2012, 8:01:36 AM7/20/12
to google-api-jav...@googlegroups.com
Nevermind - I solved my problem by specifying the path of the request as follows:

var request = gapi.client.request({
 path: '/language/translate/v2',
 method: 'GET',
 params: { q: document.getElementById('source').value,
           target: 'fr' }
});
Reply all
Reply to author
Forward
0 new messages