0

I have the same code (more or less) working fine in Java, but when I write it in javascript, I end up with 404's. I can't figure out what I'm doing wrong and it's driving me crazy!

    gapi.client.load('translate', 'v2', function () {
        gapi.client.language.languages.list().execute(function (response) {
            response.data.forEach(function(language){
                console.log(JSON.stringify(language));
            });
        });

"language":

{"code":404,"message":"Not Found","data":[{"domain":"global","reason":"notFound","message":"Not Found"}],"error":{"code":404,"message":"Not Found","data":[{"domain":"global","reason":"notFound","message":"Not Found"}]}}

I can see in the console the following POST data to https://content.googleapis.com/rpc?key=MY_API_KEY:

[{"jsonrpc":"2.0","id":"gapiRpc","method":"language.languages.list","apiVersion":"v1"}]

Should that say v1?

By contrast, the REST URL is https://www.googleapis.com/language/translate/v2/languages?key=MY_API_KEY (and it's a GET) and it works fine.

Jayen
  • 5,653
  • 2
  • 44
  • 65
  • You might want to try using a tool like Fiddler and see what urls are being requested that return the 404 and if those urls make sense in your context – Stephen James Oct 07 '13 at 10:57
  • The URL's don't match the REST API, but they look like they make sense. But what's the point of using the API if I have to look at the URL's? – Jayen Oct 07 '13 at 11:02
  • Can you post the two different URLs in your question? I agree with you, but in the spirit of diagnosis : have you tried to visit these non-matching URLs through different means (curl'ing or something) than just the client JavaScript API to check this out? Is there any possibility that the client API url set contains something that your firewall would block? – Stephen James Oct 07 '13 at 11:37
  • 1
    @StephenJames thanks! i used curl on the URL that the js api is using and I can see that if I change the POST data to have `v2` instead of `v1`, it works! Google has a bug! – Jayen Oct 07 '13 at 20:34

1 Answers1

1

You are right that this was a bug in gapi.client.load. This bug has been fixed and you should no longer run into 404s.

J P
  • 26
  • 1