Skip to content

Commit

Permalink
Make Translate auth documentation clear and consistent
Browse files Browse the repository at this point in the history
Additional updates prompted by googleapis#1594 / googleapis#2147.
  • Loading branch information
tcoffee-google committed Jun 30, 2017
1 parent b36bfb5 commit b89d7d1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Storage storage = StorageOptions.getDefaultInstance().getService();
```

If no credentials are provided, `google-cloud` will attempt to detect them from the environment
using `GoogleCredentials.getApplicationDefault()` which will search for Default Application
using `GoogleCredentials.getApplicationDefault()` which will search for Application Default
Credentials in the following locations (in order):
1. The credentials file pointed to by the `GOOGLE_APPLICATION_CREDENTIALS` environment variable
Expand Down Expand Up @@ -497,8 +497,8 @@ Google Cloud Language (Beta)
### Preview
Here is a code snippet showing a simple usage example of LanguageServiceClient. The example assumes that either default application
credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
Here is a code snippet showing a simple usage example of LanguageServiceClient. The example assumes that either Application Default
Credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
```java
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
Document document = Document.newBuilder().build();
Expand All @@ -515,7 +515,7 @@ Google Cloud Vision (Beta)
### Preview
Here is a code snippet showing a simple usage example of ImageAnnotatorClient.
The example assumes that either default application credentials or a valid API key
The example assumes that either Application Default Credentials or a valid API key
are available. (See [Authentication section](#authentication) for more information)
```java
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
Expand Down Expand Up @@ -731,8 +731,8 @@ Google Translation (Beta)
#### Preview
Here's a snippet showing a simple usage example. The example shows how to detect the language of
some text and how to translate some text. The example assumes that either default application
credentials or a valid API key are available. An API key stored in the `GOOGLE_API_KEY` environment
some text and how to translate some text. The example assumes that either Application Default
Credentials or a valid API key are available. An API key stored in the `GOOGLE_API_KEY` environment
variable will be automatically detected. Complete source code can be found at
[DetectLanguageAndTranslate.java](./google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java).
Expand Down Expand Up @@ -764,8 +764,8 @@ Google Cloud Speech (Alpha)
### Preview
Here is a code snippet showing a simple usage example of SpeechClient. The example assumes that either default application
credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
Here is a code snippet showing a simple usage example of SpeechClient. The example assumes that either Application Default
Credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
Note that you must provide a uri to a FLAC audio file to run this.
```java
Expand Down Expand Up @@ -794,8 +794,8 @@ Google Cloud Trace (Alpha)
### Preview
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either default application
credentials or a valid API key are available.
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either Application Default
Credentials or a valid API key are available.
Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
```java
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
Expand All @@ -812,8 +812,8 @@ Google Cloud Video Intelligence (Alpha)
### Preview
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either default application
credentials or a valid API key are available.
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either Application Default
Credentials or a valid API key are available.
Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
```java
try (VideoIntelligenceServiceClient videoIntelligenceServiceClient =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public class DetectLanguageAndTranslate {
public static void main(String... args) {
// Create a service object
//
// Requests are authenticated using default application credentials if available; otherwise,
// using an API key from the GOOGLE_API_KEY environment variable
// If no explicit credentials or API key are set, requests are authenticated using Application
// Default Credentials if available; otherwise, using an API key from the GOOGLE_API_KEY
// environment variable
Translate translate = TranslateOptions.getDefaultInstance().getService();

// Detect the language of some text
Expand Down
6 changes: 3 additions & 3 deletions google-cloud-translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ section to add `google-cloud-translate` as a dependency in your code.

#### Creating an authorized service object
To make authenticated requests to Google Translation, you must create a service object with
credentials or with an API key. The simplest way to authenticate is to use
credentials or use an API key. The simplest way to authenticate is to use
[Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).
These credentials are automatically inferred from your environment, so you only need the following
code to create your service object:
Expand Down Expand Up @@ -142,8 +142,8 @@ Translation translation = translate.translate(

In
[DetectLanguageAndTranslate.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java)
we put together all the code shown above into one program. The program assumes that either default
application credentials or a valid api key are available.
we put together all the code shown above into one program. The program assumes that either Application
Default Credentials or a valid API key are available.

Troubleshooting
---------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
* A client to Google Translation.
*
* <p>Here's a simple usage example for using google-cloud. This example shows how to detect the
* language of some text and how to translate some text. The example assumes that the
* {@code GOOGLE_API_KEY} is set and contains a valid API key. Alternatively, you can use
* language of some text and how to translate some text. The example assumes that either Application
* Default Credentials are available or that the {@code GOOGLE_API_KEY} environment variable is set
* and contains a valid API key. Alternatively, you can use
* {@link ServiceOptions.Builder#setCredentials setCredentials} to set credentials, or
* {@link com.google.cloud.translate.TranslateOptions.Builder#setApiKey(java.lang.String)} to set
* the API key. For the complete source code see
* <a href="https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java">
* DetectLanguageAndTranslate.java</a>.
* <pre> {@code
* Translate translate = TranslateOptions.getDefaultInstance().getService();
* an API key. For the complete source code see <a
* href="https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java">
* DetectLanguageAndTranslate.java</a>. <pre>
* {@code Translate translate = TranslateOptions.getDefaultInstance().getService();
*
* Detection detection = translate.detect("Hola");
* String detectedLanguage = detection.getLanguage();
Expand Down

0 comments on commit b89d7d1

Please sign in to comment.