Google Translate service account 403 dailyLimitExceeded error

空扰寡人 提交于 2019-12-13 07:58:57

问题


I'm configuring a Node.JS server to use the Google Translate API. So far, I've done the following:

  1. Set up a Google account
  2. Add credit card and enable billing
  3. Create a project
  4. Enable Google Translate API for project
  5. Create two service accounts for project* and save the JSON key files

*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?


回答1:


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.



来源:https://stackoverflow.com/questions/42500337/google-translate-service-account-403-dailylimitexceeded-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!