Google JavaScript API返回404

时间:2013-10-07 10:54:49

标签: google-api google-translate google-api-js-client

我有相同的代码(或多或少)在Java中运行良好,但是当我用javascript编写它时,我最终得到了404。我无法弄清楚我做错了什么,这让我发疯了!

    gapi.client.load('translate', 'v2', function () {
        gapi.client.language.languages.list().execute(function (response) {
            response.data.forEach(function(language){
                console.log(JSON.stringify(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"}]}}

我可以在控制台中看到以下POST数据到https://content.googleapis.com/rpc?key=MY_API_KEY

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

应该说v1?

相比之下,REST URL是https://www.googleapis.com/language/translate/v2/languages?key=MY_API_KEY(它是一个GET),它可以正常工作。

1 个答案:

答案 0 :(得分:1)

你是对的,这是gapi.client.load中的一个错误。此错误已得到修复,您不应再遇到404s。