Skip to content
Browse files
docs: migrate docs from wiki (#1399)
* docs: migrate docs from wiki

* docs: update README links to gh-pages
  • Loading branch information
chingor13 committed Oct 22, 2019
1 parent d3dcfe9 commit 173adcaed0d96b3771486ee59d0b4a4cf87df895
Showing with 1,371 additions and 2 deletions.
  1. +0 −2 .gitignore
  2. +2 −0 docs/_config.yml
  3. +23 −0 docs/_data/navigation.yml
  4. +54 −0 docs/_layouts/default.html
  5. +69 −0 docs/
  6. +43 −0 docs/
  7. +64 −0 docs/
  8. +52 −0 docs/
  9. +59 −0 docs/
  10. +77 −0 docs/
  11. +88 −0 docs/
  12. +112 −0 docs/
  13. +582 −0 docs/
  14. +79 −0 docs/
  15. +67 −0 docs/
@@ -25,8 +25,6 @@ nosetests.xml

# Built documentation

# Python utilities
@@ -0,0 +1,2 @@
theme: jekyll-theme-dinky
title: Google HTTP Client for Java
@@ -0,0 +1,23 @@
- page: Overview
url: index.html
- page: Setup Instructions
url: setup.html
- page: Component Modules
url: component-modules.html
- page: Android
url: android.html
- page: Google App Engine
url: google-app-engine.html
- page: Batching
url: batching.html
- page: Media Download
url: media-download.html
- page: Media Upload
url: media-upload.html
- page: OAuth 2.0
url: oauth-2.0.html
- page: Timeouts and Errors
url: errors.html
- page: Support
url: support.html
@@ -0,0 +1,54 @@
<!doctype html>
<html lang="{{ site.lang | default: "en-US" }}">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

{% seo %}
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}">
<script src="{{ '/assets/js/scale.fix.js' | relative_url }}"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//"></script>
<div class="wrapper">
<h1 class="header">{{ site.title | default: site.github.repository_name }}</h1>

{% for entry in %}
<a href="{{ entry.url }}">{{ }}</a><br/>
{% endfor %}

{% if site.show_downloads %}
<li class="download"><a class="buttons" href="{{ site.github.zip_url }}">Download ZIP</a></li>
<li class="download"><a class="buttons" href="{{ site.github.tar_url }}">Download TAR</a></li>
{% endif %}
<li><a class="buttons github" href="{{ site.github.repository_url }}">View On GitHub</a></li>

{{ content }}

<p><small>Hosted on <a href="">GitHub Pages</a> using the Dinky theme</small></p>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
{% if site.google_analytics %}
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
ga('create', '{{ site.google_analytics }}', 'auto');
ga('send', 'pageview');
{% endif %}
@@ -0,0 +1,69 @@
title: Android

# Running on [Android (@Beta)](#@Beta)

If you are developing for Android and the Google API you want to use is included
in the [Google Play Services library][play-services], use that library for the
best performance and experience.

To access other Google APIs, use the Google Client Library for Java's
Android-specific helper classes, which are well-integrated with
[Android AccountManager][account-manager].

For example:

public void onCreate(Bundle savedInstanceState) {
// Google Accounts
credential =
GoogleAccountCredential.usingOAuth2(this, Collections.singleton(TasksScopes.TASKS));
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
// Tasks client
service =
new, jsonFactory, credential)

## Getting started

Begin by reading the [Android development instructions][http-client-android] for
the Google HTTP Client Library for Java.

## Authentication

As described in the [Android development instructions][http-client-android], the
best practice on Android is to use the [`AccountManager`][account-manager] class
(`@Beta`) for centralized identity management and credential token storage.

For information about the OAuth 2.0 flow, see the
[OAuth 2.0 instructions for Android][oauth2-android].

## Partial response and update

Google APIs support a partial-response protocol that allows you to specify which
fields are returned to you in the HTTP response. This can significantly reduce
the size of the response, thereby reducing network usage, parsing response time,
and memory usage. It works with both JSON and XML.

The following snippet of code drawn from the Google+ Sample demonstrates how to
use the partial-response protocol:

Plus.Activities.List listActivities = plus.activities().list("me", "public");
// Pro tip: Use partial responses to improve response time considerably
ActivityFeed feed = listActivities.execute();

@@ -0,0 +1,43 @@
title: Batching

# Batching

Each HTTP connection that your client makes results in overhead. To reduce
overhead, you can batch multiple API calls together into a single HTTP request.

The main classes of interest are [BatchRequest][batch-request] and
[JsonBatchCallback][json-batch-callback]. The following example shows how to use
these classes with service-specific generated libraries:

JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() {
public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) {
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
System.out.println("Error Message: " + e.getMessage());
Calendar client = Calendar.builder(transport, jsonFactory, credential)
BatchRequest batch = client.batch();
Calendar entry1 = new Calendar().setSummary("Calendar for Testing 1");
client.calendars().insert(entry1).queue(batch, callback);
Calendar entry2 = new Calendar().setSummary("Calendar for Testing 2");
client.calendars().insert(entry2).queue(batch, callback);

@@ -0,0 +1,64 @@
title: Component Modules

# Component Modules

This libraries is composed of several modules:

## google-api-client

The Google API Client Library for Java (`google-api-client`) is designed to be
compatible with all supported Java platforms, including Android.

## google-api-client-android

Extensions to the Google API Client Library for Java
(`google-api-client-android`) support Java Google Android (only for SDK >= 2.1)
applications. This module depends on `google-api-client` and

## google-api-client-servlet

Servlet and JDO extensions to the Google API Client Library for Java
(`google-api-client-servlet`) support Java servlet web applications. This module
depends on `google-api-client` and `google-oauth-client-servlet`.

## google-api-client-appengine

Google App Engine extensions to the Google API Client Library for Java
(`google-api-client-appengine`) support Java Google App Engine applications.
This module depends on `google-api-client`, `google-api-client-servlet`,
`google-oauth-client-appengine`, and `google-http-client-appengine`.

## google-api-client-gson

GSON extensions to the Google API Client Library for Java
(`google-api-client-gson`). This module depends on `google-api-client` and

## google-api-client-jackson2

Jackson2 extensions to the Google API Client Library for Java
(`google-api-client-jackson2`). This module depends on `google-api-client` and

## google-api-client-java6

Java 6 (and higher) extensions to the Google API Client Library for Java
(`google-api-client-java6`). This module depends on `google-api-client` and

## google-api-client-protobuf

[Protocol buffer][protobuf] extensions to the Google API Client Library for Java
(`google-api-client-protobuf`). This module depends on
`google-http-client-protobuf` and `google-api-client`.

## google-api-client-xml

XML extensions to the Google API Client Library for Java
(`google-api-client-xml`). This module depends on `google-api-client` and

@@ -0,0 +1,52 @@
title: Timeout and Errors

# Timeout and Errors

## Setting timeouts

In the following example, which uses the
[Google Analytics API][google-analytics-api], the `setConnectTimeout` and
`setReadTimeout` methods are used to set the connect and read timeouts to three
minutes (in milliseconds) for all requests:

private HttpRequestInitializer setHttpTimeout(final HttpRequestInitializer requestInitializer) {
return new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) throws IOException {
httpRequest.setConnectTimeout(3 * 60000); // 3 minutes connect timeout
httpRequest.setReadTimeout(3 * 60000); // 3 minutes read timeout
GoogleCredential credential = ....
final Analytics analytics = Analytics.builder(new NetHttpTransport(), jsonFactory, setHttpTimeout(credential)).build();
## Handling HTTP error responses from Google APIs
When an error status code is detected in an HTTP response to a Google API that
uses the JSON format, the generated libraries throw a
The errors use the format specified in [Error responses][error-responses].
The following example shows one way that you can handle these exceptions:
Plus.Activities.List listActivities = plus.activities().list("me", "public");
try {
ActivityFeed feed = listActivities.execute();
} catch (GoogleJsonResponseException e) {
@@ -0,0 +1,59 @@
title: Running on Google App Engine

# Running on Google App Engine

App Engine-specific helpers make quick work of authenticated calls to APIs, and
you do not need to worry about exchanging code for tokens.

For example:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
AppIdentityCredential credential =
new AppIdentityCredential(Arrays.asList(UrlshortenerScopes.URLSHORTENER));
Urlshortener shortener =
new Urlshortener.Builder(new UrlFetchTransport(), new JacksonFactory(), credential)
UrlHistory history = shortener.URL().list().execute();

## Auth helpers

If you are building a web app that interacts with a user's data via an OAuth
2.0-enabled API, we've created some helpers to assist you with the process. The
helpers aim to:

* Simplify the process of obtaining access tokens
* Manage tokens, after they are obtained, by marking them as
* Simplify the process of making authenticated calls using the access token's
* Insulate you from the details of authentication when writing servlets.

## Getting started

1. Install the Google API Client Library for Java:
* Follow the [download instructions][setup] and put the library jar files
into your war/WEB-INF/lib directory.
* Alternatively, you can use [Maven][setup].
1. Learn about using [OAuth 2.0 with the authorization code flow for Google App Engine applications][oauth2].
1. Learn about using [OAuth 2.0 with the Google App Engine Identity API][oauth2-gae].
1. Take a look at the [Calendar App Engine sample][calendar-sample]. This sample
combines our Java library and auth helpers to show you how to access end-user
data from within a Google App Engine web app. The sample also uses [GWT][gwt]
for the user interface.


0 comments on commit 173adca

Please sign in to comment.