Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google API Key for translation

Tags:

google-api

what key (if any) do I require for simple text translation from program?

Note: I don't host any website.

like image 488
user13323 Avatar asked Jan 31 '11 18:01

user13323


2 Answers

Getting a Google Translate API Key

To use the Google API, you first need a Google Cloud account.

  1. Go to https://cloud.google.com/translate/docs/basic/setup-basic
  2. Click Set up a project.
  3. Name the new project in the Enable Cloud Translation API screen. Use this dialog to name your project
  4. They may ask you to create or connect to an existing billing account. Google gives you a $300 credit to use the Cloud Translation API over a year to try it out.
  5. Create a new service account.
  6. This screen will pop up with your new project name and the associated service account. Click Download Private Key. This API key (written in JSON) connects your site to the Google Cloud. To enable API, download the private key.
  7. Upload the Google Translate API key to your site. Check with your hosting company where on your system to place this key.
  8. When you’ve placed the Google API key on your site, tell your system where to find it. Set an environment variable. Again, check with your hosting company if you don’t know how to open a terminal.

API keys are the same for all GCP APIs. Instructions here: https://cloud.google.com/docs/authentication/api-keys

Activate the Google Translate API

Before you can use a Google API in your project, you have to activate it. Go to the side menu and select the APIs & Services option:

enter image description here

Now you will see a screen with statistics about the APIs that you have activated. If you created the project from scratch by following the steps above, you won’t have any data yet, as you can see:

enter image description here

Click on the upper button Enable APIs and services to continue with the activation process of the API. This takes us to a search box where we have to look for the API we’re interested in. In this case, we want to use the Google Translate API. Type translate in the search box and click on the result Cloud Translate API:

enter image description here

This brings us to a screen with the description of the Cloud Translation API. Click on the Enable button to activate the API in our project:

enter image description here

We already have the Google Cloud Translation API activated. We’re almost there…

Create a new API Key for Google Translate

After activating the API, let’s see how to generate a new Key API to be able to use this service. We have to go to the side menu again and select the Credentials option:

enter image description here

On this screen we see a button with a drop-down and the text Create credentials. Don’t click on the button! Instead, open the drop-down by clicking on the arrow to the right of the button and select the API Key option.

enter image description here

This creates the new Key API. You can copy it if you want, although you can access it later:

enter image description here

Google Cloud provides us with a new Key API to use Google Translate with our third-party applications.

How to Restrict Our API Key to Protect and Limit Its Use

To control the cost of Google Cloud by using the Google Cloud Translation API (or Google Translate, which is the same), we can do two things: restrict where you can use the API Key that we just created or limit the allowed quota to use the service itself.

In the screenshot above, if you click on the Restrict Key button you will go to the API Key restriction screen that follows:

enter image description here

There you can select to restrict the API Key by HTTP referrers, which means that you can only make calls to the Google Cloud Translate API using the API Key from certain domain names.

You must add the valid domain names in the text box that appears when selecting the HTTP referrers option. Sample domain name https://google.com/*.

On the other hand, go to the menu API’s & Services → Dashboard → Cloud Translation API → Quotas and there you will find a box called Characters. There you can modify the quota limits of the Google Cloud Translation API and reduce them, if necessary.

The price for Google Cloud Translation API at the time of writing this post is 20 USD per million translated characters, so make your numbers.

enter image description here

And that’s all! You already have your API Key ready to be used with the application you want. The process is a bit cumbersome at first, but following the steps you’ll get the API Key without problems.

like image 107
Lakshman Kambam Avatar answered Oct 05 '22 16:10

Lakshman Kambam


An API key is required to use the Google Translate API and you can get yours from the Google APIs Console.

For further details, check the Developer's Guide.

like image 37
Claudio Cherubino Avatar answered Oct 05 '22 16:10

Claudio Cherubino