node.jsgoogle-cloud-platformgoogle-apigoogle-translategoogle-translation-api

Google Translate API v3: how to authenticate with private_key from Service Account Key?


How to authenticate to Google Translate API v3 with private_key from Service Account Key? As v3 doesn't work with api keys there should be a way of authentication but with private_key


Solution

  • import { TranslationServiceClient } from '@google-cloud/translate';
    
    const credentials = {
     client_email: <your_service_account_email>,
     private_key: <your_private_key_from_service_account_key>
    };
    
    const translationClient = new TranslationServiceClient({
        credentials,
    });
    
    // now you can use translationClient to perform translations