【问题标题】:403 daily quota for Google Translation APIGoogle Translation API 每日 403 配额
【发布时间】:2017-12-26 01:04:04
【问题描述】:

我关注了instructions 使用 Google Translate API。我有:

  1. 创建了一个项目
  2. 已启用结算功能并在结算帐户上有 300 美元
  3. 启用翻译 API 并确保配额很高
  4. 生成了一个具有管理员角色的服务帐户并下载了 JSON
  5. 将以下行添加到我的 .zshrc:

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

    source ~/.zshrc
    

然而我的 nodeJS 代码和我的 curl 都返回了:

 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 密钥和谷歌群组论坛(它的设计只是让我更欣赏 StackOverflow... :))

----更新----

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

【问题讨论】:

    标签: google-cloud-platform google-translate


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        您可以通过配额解决此问题。你应该增加“每天字符数”和“每秒字符数”。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-01-19
          • 1970-01-01
          • 2019-02-23
          • 1970-01-01
          • 2016-11-08
          • 2018-07-18
          • 1970-01-01
          相关资源
          最近更新 更多