Google Code blog Version 1.5 release of Java client library released today now come with the open source Google OAuth Client Library for Java in Beta, with support for both OAuth 1.0a and OAuth 2.0, announced Google Code blog.
“OAuth is an open standard for allowing a client application to securely gain access to a user’s private data stored on Google without ever asking for their password.”
“Most Google APIs support OAuth 2.0, and we want to encourage adoption of OAuth 2.0 more widely on the web. That’s why we built this library to work with any API on the web — not just Google APIs — that comply with the OAuth specifications,” informed Yaniv Inbar, Google APIs Client Team.
Finally, the team also made available a Beta version of the open source Google HTTP Client Library for Java.
“This is the common HTTP client library that the above two libraries are built on, and is built to work with any API on the web.
It features a pluggable HTTP transport abstraction that allows it to work seamlessly on any of the supported Java platforms, support for efficient JSON and XML data models for parsing and serialization, and a pluggable JSON and XML parser so you can use whatever works best for you,” Yaniv stated.
// Set up the HTTP transport and JSON factory HttpTransport httpTransport = new NetHttpTransport(); JsonFactory jsonFactory = new JacksonFactory(); // Set up OAuth 2.0 access of protected resources // using the refresh and access tokens, automatically // refreshing the access token when it expires GoogleAccessProtectedResource requestInitializer = new GoogleAccessProtectedResource(accessToken, httpTransport, jsonFactory, clientId, clientSecret, refreshToken); // Set up the main Google+ class Plus plus = new Plus(httpTransport, requestInitializer, jsonFactory); // Make a request to access your profile and display it to console Person profile = plus.people().get("me").execute(); System.out.println("ID: " + profile.getId()); System.out.println("Name: " + profile.getDisplayName()); System.out.println("Image URL: " + profile.getImage().getUrl()); System.out.println("Profile URL: " + profile.getUrl());