Google 翻译 API 的 403 每日配额

403 daily quota for Google Translation API

我按照 instructions 使用 Google 翻译 API。我有:

  1. 创建了一个项目
  2. 启用计费并且计费帐户中有 300 美元
  3. 启用翻译API并确保配额较高
  4. 生成了一个具有管理员角色的服务帐户并下载了 JSON
  5. 向我的 .zshrc 添加了以下行:

    export GOOGLE_APPLICATION_CREDENTIALS=/pathto/Holodeck-421412.json
    
  6. 来源:

    source ~/.zshrc
    

然而我的 nodeJS 代码和我的 curl return:

 code: 403,
  errors:
   [ { message: 'Daily Limit Exceeded',
       domain: 'usageLimits',
       reason: 'dailyLimitExceeded' } ],
  response: undefined,
  message: 'Daily Limit Exceeded' }

我的卷曲:

curl --header "Content-Type: application/json" --header "Authorization: Bearer `gcloud auth print-access-token`" --show-error -s "https://translation.googleapis.com/language/translate/v2" -d @translate-request.json

并翻译-request.json:

{
  "q": "The quick brown fox jumped over the lazy dog.",
  "source": "en",
  "target": "es",
  "format": "text"
}

我的 NodeJS 代码:

// Imports the Google Cloud client library
const language = require('@google-cloud/language');
const Translate = require('@google-cloud/translate');

// Instantiates a client
const client = new language.LanguageServiceClient();

// Your Google Cloud Platform project ID
const projectId = 'myproject ID';

// Instantiates a client
const translation = new Translate({
    projectId: projectId
});


// The text to analyze
let text1 = 'Hello, world!';

const translate = (text) => {
    const target = 'en';

    translation
        .translate(text, target)
        .then(results => {
            const translation = results[0];

            console.log(`Text: ${text}`);
            console.log(`Translation: ${translation}`);
        })
        .catch(err => {
            console.error('ERROR:', err);
        });
}


const analyze = (text) => {

    const document = {
        content: "good very good amazingly good",
        type: 'PLAIN_TEXT',
    };

// Detects the sentiment of the text
    client
        .analyzeSentiment({document: document})
        .then(results => {
            const sentiment = results[0].documentSentiment;
            console.log(`Sentiment score: ${sentiment.score}`);
            console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
        })
        .catch(err => {
            console.error('ERROR:', err);
        });
}

translate(text1);
analyze(text1);

我很困惑,因为自然语言 API 正在工作,所以服务帐户似乎运行正常。对此有任何看法吗?我花了 3 个小时试图通过这个意想不到的障碍,我已经完成了所有我能想到的剃毛,包括打开新项目/服务帐户/API 密钥和 google 组论坛(它的设计只是让我更加欣赏 Whosebug...:))

----更新----

当我将每天字符的配额从 1,000,000 更改为另一个值时,API 似乎开始工作 15 秒左右(2-3 次请求)然后返回到 403 错误。然后,如果我再次更改配额,我会收到另一轮 2-3 个请求。好像请求本身正在更改配额或更改在 15-20 秒后撤消。

我遇到了同样的问题,我在 Google 问题跟踪器中发现了这个错误:https://issuetracker.google.com/issues/70990743

问题现在应该已经解决了,请再试一次看看你是否仍然看到这个问题,并在必要时重新打开问题 #70990743

你可以用配额解决这个问题。你应该增加 "character per day" 和 "character per second".