You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/translate/README.md
+67-3Lines changed: 67 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,14 @@
6
6
-[API Documentation][gcloud-translate-docs]
7
7
-[Official Documentation][cloud-translate-docs]
8
8
9
-
**An API key is required for Translate.** See [Identifying your application to Google][api-key-howto].
10
-
11
9
12
10
```sh
13
11
$ npm install --save @google-cloud/translate
14
12
```
15
13
```js
16
14
var translate =require('@google-cloud/translate')({
17
-
key:'API Key'
15
+
projectId:'grape-spaceship-123',
16
+
keyFilename:'/path/to/keyfile.json'
18
17
});
19
18
20
19
// Translate a string of text.
@@ -59,6 +58,71 @@ var translate = require('@google-cloud/translate')({
59
58
```
60
59
61
60
61
+
## Authentication
62
+
63
+
It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Google Cloud services.
64
+
65
+
### On Google Compute Engine
66
+
67
+
If you are running this client on Google Compute Engine, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access.
68
+
69
+
```js
70
+
// Authenticating on a global basis.
71
+
var projectId =process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
72
+
73
+
var translate =require('@google-cloud/translate')({
74
+
projectId: projectId
75
+
});
76
+
77
+
// ...you're good to go!
78
+
```
79
+
80
+
### With a Google Developers Service Account
81
+
82
+
If you are not running this client on Google Compute Engine, you need a Google Developers service account. To create a service account:
83
+
84
+
1. Visit the [Google Developers Console][dev-console].
85
+
2. Create a new project or click on an existing project.
86
+
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
87
+
* Google Translate API
88
+
4. Navigate to **APIs & auth** > **Credentials** and then:
89
+
* If you want to use a new service account, click on **Create new Client ID** and select **Service account**. After the account is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests.
90
+
* If you want to generate a new key for an existing service account, click on **Generate new JSON key** and download the JSON key file.
91
+
92
+
```js
93
+
var projectId =process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
94
+
95
+
var translate =require('@google-cloud/translate')({
96
+
projectId: projectId,
97
+
98
+
// The path to your key file:
99
+
keyFilename:'/path/to/keyfile.json'
100
+
101
+
// Or the contents of the key file:
102
+
credentials:require('./path/to/keyfile.json')
103
+
});
104
+
105
+
// ...you're good to go!
106
+
```
107
+
108
+
### With an API key
109
+
110
+
It's also possible to authenticate with an API key. To create an API key:
111
+
112
+
1. Visit the [Google Developers Console][dev-console].
113
+
2.2. Create a new project or click on an existing project.
114
+
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
115
+
* Google Translate API
116
+
4. Navigate to **APIs & auth** > **Credentials** and then click on **Create new Client ID** and select **API key**. You should then be presented with a pop-up containing your newly created key.
117
+
118
+
```js
119
+
var translate =require('@google-cloud/translate')({
Copy file name to clipboardExpand all lines: packages/translate/src/index.js
+7-19Lines changed: 7 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -41,9 +41,6 @@ var PKG = require('../package.json');
41
41
* [Pricing](https://cloud.google.com/translate/v2/pricing.html) and
42
42
* [FAQ](https://cloud.google.com/translate/v2/faq.html) pages for details.
43
43
*
44
-
* **An API key is required for Translate.** See
45
-
* [Identifying your application to Google](https://cloud.google.com/translate/v2/using_rest#auth).
46
-
*
47
44
* @constructor
48
45
* @alias module:translate
49
46
*
@@ -53,7 +50,7 @@ var PKG = require('../package.json');
0 commit comments