我有相同的代码(或多或少)在 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)并且工作正常。