I'm configuring a Node.JS server to use the Google Translate API. So far, I've done the following:
*One service account for local development and one account for deployed application.
Sample code (Typescript):
import * as Translate from '@google-cloud/translate';
export async function translate(text: string, to: string): Promise<string> {
let translation = '';
const googleTranslate = Translate({
projectId: PROJECT_ID,
keyFilename: PATH/TO/KEY_FILE
});
const response = await googleTranslate.translate(text, to);
if (Array.isArray(response[0])) {
for (let t of response[0]) {
translation += t;
}
}
else {
translation = response[0];
}
return translation;
}
I tested both the local and dev key on my workstation and successfully translated. However, it does not work in a deployed environment (different machine, dynamic IP). The following error occurs:
Error response:
{
domain: 'usageLimits',
reason: 'dailyLimitExceeded',
message: 'This API requires billing to be enabled on the project. Visit https://console.developers.google.com/billing?project=GOOGLE_PROJECT_ID to enable billing.',
extendedHelp: 'https://console.developers.google.com/billing?project=project=GOOGLE_PROJECT_ID'
}
Billing is enabled so what am I missing?
Resolved!
Unescaped characters in the private key were breaking inside a Chef cookbook recipe. A different process now syncs the file to the server on initialization, and translation works.