@@ -17,17 +17,34 @@ Setup
17
17
Authentication
18
18
++++++++++++++
19
19
20
- Authentication for this service is done via an `API Key `_. To obtain an API
21
- Key:
20
+ Authentication is typically done through `Application Default Credentials `_,
21
+ which means you do not have to change the code to authenticate as long as
22
+ your environment has credentials. You have a few options for setting up
23
+ authentication:
22
24
23
- 1. Open the `Cloud Platform Console `_
24
- 2. Make sure that billing is enabled for your project.
25
- 3. From the **Credentials ** page, create a new **API Key ** or use an existing
26
- one for your project.
25
+ #. When running locally, use the `Google Cloud SDK `_
27
26
28
- .. _API Key :
29
- https://developers.google.com/api-client-library/python/guide/aaa_apikeys
30
- .. _Cloud Console : https://console.cloud.google.com/project?_
27
+ .. code-block :: bash
28
+
29
+ gcloud beta auth application-default login
30
+
31
+
32
+ #. When running on App Engine or Compute Engine, credentials are already
33
+ set-up. However, you may need to configure your Compute Engine instance
34
+ with `additional scopes `_.
35
+
36
+ #. You can create a `Service Account key file `_. This file can be used to
37
+ authenticate to Google Cloud Platform services from any environment. To use
38
+ the file, set the ``GOOGLE_APPLICATION_CREDENTIALS `` environment variable to
39
+ the path to the key file, for example:
40
+
41
+ .. code-block :: bash
42
+
43
+ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
44
+
45
+ .. _Application Default Credentials : https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
46
+ .. _additional scopes : https://cloud.google.com/compute/docs/authentication#using
47
+ .. _Service Account key file : https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
31
48
32
49
Install Dependencies
33
50
++++++++++++++++++++
@@ -77,7 +94,6 @@ To run this sample:
77
94
$ python snippets.py
78
95
79
96
usage: snippets.py [-h]
80
- api_key
81
97
{detect-language,list-languages,list-languages-with-target,translate-text}
82
98
...
83
99
@@ -88,7 +104,6 @@ To run this sample:
88
104
https://cloud.google.com/translate/docs.
89
105
90
106
positional arguments:
91
- api_key Your API key.
92
107
{detect-language,list-languages,list-languages-with-target,translate-text}
93
108
detect-language Detects the text' s language.
94
109
list-languages Lists all available languages.
0 commit comments