Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Search
Google Health Data API (Deprecated) Home Docs FAQ Articles Forum Terms
Java 1.5 The Google Health Data API allows client applications to view and update Health content
Java 1.4.2 in the form of Google Data API feeds. Your client application can request a user's profile
as a CCR document, retrieve a list of notices sent to their account, or send a notice to a
Reference Guide (v2.0)
user.
API Changelog
In addition to providing some background on the capabilities of the Health Data API, this
Libraries and Code
document provides examples for interacting with the API using the Java client library.
Previous Versions This document provides Java 1.5 specifics for performing the general actions described in
CCR Reference the developer's guide overview page.
Getting started
For help getting started with Google Data API Java client library, see Getting Started with
the Java Client Library.
To use the Java client library, you must be running Java 1.5 or higher. You must also be
running Apache Ant, and either a servlet container such as Apache Tomcat or full app
server such as JBoss.
In addition, you should download the following libraries and update the relevant
build.properties files to point to the correct location of the dependencies.
Download the full source code of a working sample application that works with the H9
Sandbox.
The client library
Sun's Java Activation Framework (JAF)
Sun's Java Mail API
Sun's Servlet API library
The collections, configuration and lang Jakarta Commons libraries
The Jakarta Standard 1.1 Taglib
To build the application, use the included build.xml file with Apache Ant to compile a
WAR file in the deploy directory. Deploy this file to your servlet container. Tomcat's
default configuration, for example, will auto-deploy the war file if it is copied to
root/webapps.
Note: The sample application currently doesn't have much error feedback to the end-
user visiting the application. Most exceptions are caught and logged to stderr, so
please look at the server error logs if you are experiencing any problems with this
application. In Tomcat, for instance, these errors would be logged to
catalina_root/logs/catalina.out.
Error handling has been removed from this document. To see a complete implementation,
including error handling, download the full source sample.
Back to top
AuthSub Authentication
The AuthSub login protocol allows your web-based application to have a user
authenticate through Google's servers.
The following code sets a service object for H9 and generates an AuthSub URL:
The single parameter is the name of your application in the form companyName-
applicationName-versionID.
If you're ready to move to production, here's how to set a service object for Health and
generate the AuthSub URL:
Note: Before you can interact with Google Health, you must register your application
with Google and Google Health. Please see Domain Registration & Signing Requests
in the Getting Started Guide.
To extract the single-use token and exchange it for a session token, use the following on
H9:
String singleUseToken =
AuthSubUtil.getTokenFromReply(httpServletRequest.getQueryString());
String sessionToken =
AuthSubUtil.exchangeForSessionToken(URLDecoder.decode(singleUseToken,
"UTF-8"), null);
h9Service.setAuthSubToken(sessionToken);
// query an H9 feed
This procedure is slightly for sophisticated for Google Health. The token upgrade and call
to setAuthSubToken must include your Java keystore:
String singleUseToken =
AuthSubUtil.getTokenFromReply(httpServletRequest.getQueryString());
PrivateKey privateKey =
AuthSubUtil.getPrivateKeyFromKeystore("keystore.jks", "keystorePass",
"keyAlias", "keyPass");
String sessionToken =
AuthSubUtil.exchangeForSessionToken(URLDecoder.decode(singleUseToken,
"UTF-8"), privateKey);
healthService.setAuthSubToken(sessionToken, privateKey);
The call to setAuthSubToken sets the healthService object with the session token
and your privateKey. You don't need to worry about setting these values on
subsequent requests.
For help creating a the keystore file, see Creating a self-signing X.509 public certificate in
the Getting Started Guide.
For H9:
In the snippets above, we pass a single parameter to the service constructor, the name of
our application in the form companyName-applicationName-versionID.
For more information about ClientLogin authentication, including sample requests and
responses, see the Authentication for Installed Applications documentation.
Note: Use the same token for all requests in a given session; don't acquire a new
token for each Health request.
information stored with Google. Each profile is encapsulated inside of an Atom entry. The
Java client library can be used to extract the CCR information and print it to the page.
The following example shows how to query the profile feed using AuthSub. It assumes
that the HealthService constructor has already been called and set to
healthService.
try {
ProfileFeed result = healthService.getFeed(query,
ProfileFeed.class);
System.out.println(entry.getContinuityOfCareRecord().getXmlBlob().getB
lob());
}
}
...
For installed desktop/mobile applications using ClientLogin, work with the profile/ui
feed instead of the profile/default feed.
System.out.println(entry.getContinuityOfCareRecord().getXmlBlob().getB
lob());
}
Back to top
You can retrieve notices that your application has access to view using the register feed
in conjunction with a profile ID: register/ui/profileID. Note that you can use query
parameters to narrow down the results of this query.
The following code retrieves all of the notices associated with the given profile. It also
prints out any attached CCR data appended to a notice.
try {
RegisterFeed result = healthService.query(query,
RegisterFeed.class);
...
Send a notice
Creating a new notice is accomplished by constructing an Atom entry and sending an
HTTP POST to the register feed.
CCR data can be included with your notice. The below code shows adding a CCR
fragment from a string variable called ccr.
newNotice.setTitle(new PlainTextConstruct(yourSubject));
newNotice.setContent(new PlainTextConstruct(yourMessage));
if (ccr != null) {
XmlBlob ccrElement = new XmlBlob();
ccrElement.setBlob(ccr);
newNotice.setXmlBlob(ccrElement);
try {
Entry createdNotice = service.insert(new
URL("https://www.google.com/health/feeds/register/default"),
newNotice);
}
...
Back to top
2011 Google - Code Home - Site Terms of Service - Privacy Policy - Site Directory