Google翻译服务帐户403 dailyLimitExceeded错误

时间:2017-02-28 04:39:50

标签: amazon-ec2 chef google-translate google-api-nodejs-client

我正在配置Node.JS服务器以使用Google Translate API。到目前为止,我已经完成了以下工作:

  1. 设置Google帐户
  2. 添加信用卡并启用结算
  3. 创建项目
  4. 为项目启用Google Translate API
  5. 为project *创建两个服务帐户并保存JSON密钥文件
  6. *一个用于本地开发的服务帐户和一个用于已部署应用程序的帐户。

    示例代码(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;
    
    }
    

    我在我的工作站上测试了本地和开发键并成功翻译了。 但是,它在部署环境(不同的计算机,动态IP)中不起作用。发生以下错误:

    错误回复:

    {
        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'
    }
    

    结算已启用,所以我缺少什么?

1 个答案:

答案 0 :(得分:0)

解决!

私钥中未转义的字符在Chef菜谱食谱中破碎。现在,一个不同的进程在初始化时将文件同步到服务器,并且翻译工作正常。