简体   繁体   English

每日403次Google翻译API配额

[英]403 daily quota for Google Translation API

I followed the instructions for working with Google Translate API. 我按照使用Google Translate API的说明进行操作 I have: 我有:

  1. created a project 创建了一个项目
  2. enabled billing and have $300 on the billing account 启用结算功能并在结算帐户上获得300美元
  3. enabled the translation API and made sure that the quota is high 启用了转换API并确保配额很高
  4. generated a service account with an Admin role and downloaded the JSON 生成具有Admin角色的服务帐户并下载JSON
  5. added the following line to my .zshrc: 将以下行添加到我的.zshrc:

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

     source ~/.zshrc 

Yet both my nodeJS code and my curl return: 然而我的nodeJS代码和我的curl都返回:

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

My curl: 我的卷毛:

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

and translate-request.json: 和translate-request.json:

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

My NodeJS code: 我的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);

It is puzzling to me as the Natural Language API is working so the Service account seems to be functioning properly. 令我感到困惑的是,自然语言API正在运行,因此服务帐户似乎正常运行。 Any angle on this? 对此有何看法? I am 3 hours deep trying to pass this unexpected hurdle and I've done any yak shaving I could think off including opening new projects / service account / API keys and google groups forums (which it's design just make me appreciate StackOverflow more... :)) 我试图通过这个意想不到的障碍3个小时,我做了任何牦牛剃须,我可以想到包括打开新的项目/服务帐户/ API密钥和谷歌团体论坛(它的设计只是让我欣赏StackOverflow更多... :))

----UPDATE---- ---- ----更新

When I change the quota of Characters per day from 1,000,000 to another value the API seems to start working for 15 or so seconds (2-3 requests) and then goes back to the 403 error. 当我将每天字符数量从1,000,000更改为另一个值时,API似乎开始工作15秒左右(2-3个请求),然后返回到403错误。 Then if I change the quota again I get another round of 2-3 requests. 然后,如果我再次更改配额,我会得到另一轮2-3次请求。 It is as if the request itself is changing the quota or the change is undone after 15-20 seconds. 就好像请求本身正在更改配额,或者在15-20秒后撤消更改。

配额

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

该问题应该已经修复到现在,请再试一次,看看您是否仍然看到此问题,并在必要时重新打开问题#70990743

you can solve this problem with quotas. 你可以用配额来解决这个问题。 You should increase "character per day" and "character per second". 你应该增加“每日角色”和“每秒角色”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM