Skip to content

Commit cccdfdb

Browse files
authored
README section for interop with google-http-client (#275)
Adds an example using `HttpCredentialsAdapter`
1 parent 4701056 commit cccdfdb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,24 @@ for (Bucket b : storage_service.list().iterateAll())
148148
System.out.println(b);
149149
```
150150

151+
## Using Credentials with `google-http-client`
152+
153+
Credentials provided by `google-auth-library` can be used with Google's [HTTP-based clients][apiary-clients]. We provide a [`HttpCredentialsAdapter`][http-credentials-adapter] which can be used as an [`HttpRequestInitializer`][http-request-initializer].
154+
155+
```java
156+
import com.google.api.client.http.HttpRequestInitializer;
157+
import com.google.api.services.bigquery.Bigquery;
158+
import com.google.auth.http.HttpCredentialsAdapter;
159+
import com.google.auth.oauth2.GoogleCredentials;
160+
161+
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
162+
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
163+
164+
Bigquery bq = new Bigquery.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
165+
.setApplicationName(APPLICATION_NAME)
166+
.build();
167+
```
168+
151169
## CI Status
152170

153171
Java Version | Status
@@ -186,3 +204,6 @@ BSD 3-Clause - See [LICENSE](LICENSE) for more information.
186204

187205
[appengine-sdk-versions]: https://search.maven.org/search?q=g:com.google.appengine%20AND%20a:appengine-api-1.0-sdk&core=gav
188206
[appengine-sdk-install]: https://github.com/googleapis/google-auth-library-java/blob/master/README.md#google-auth-library-appengine
207+
[apiary-clients]: https://search.maven.org/search?q=g:com.google.apis
208+
[http-credentials-adapter]: https://googleapis.dev/java/google-auth-library/latest/index.html?com/google/auth/http/HttpCredentialsAdapter.html
209+
[http-request-initializer]: https://googleapis.dev/java/google-http-client/latest/index.html?com/google/api/client/http/HttpRequestInitializer.html

0 commit comments

Comments
 (0)