Reputation: 13286
I followed the instructions for working with Google Translate API. I have:
added the following line to my .zshrc:
export GOOGLE_APPLICATION_CREDENTIALS=/pathto/Holodeck-421412.json
Sourced it with:
source ~/.zshrc
Yet both my nodeJS code and my curl return:
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:
{
"q": "The quick brown fox jumped over the lazy dog.",
"source": "en",
"target": "es",
"format": "text"
}
My NodeJS code:
// 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. 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... :))
----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. Then if I change the quota again I get another round of 2-3 requests. It is as if the request itself is changing the quota or the change is undone after 15-20 seconds.
Upvotes: 1
Views: 1957
Reputation: 113
you can solve this problem with quotas. You should increase "character per day" and "character per second".
Upvotes: 1
Reputation: 1044
The issue should have been Fixed as of now, please try again to see if you're still seeing this issue and re-open the Issue #70990743 if necessary.
Upvotes: 1
Reputation: 23
I've the same issue and searching I found this bug in the Google Issue Tracker: https://issuetracker.google.com/issues/70990743
Upvotes: 1