O'Reilly logo

Developing with Google+ by Jennifer Murphy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 1. Introduction

Hello there! Since you’re reading these words, the Google+ platform has probably sparked your interest. Maybe you have a killer app in mind, or perhaps you’re just interested in learning what’s available. Either way, by the time you’re finished with this book, you will be comfortable digging into Google+.

The Google+ platform has three categories of features. Each of these categories is capable of standing alone, but things become more interesting when you combine them. These categories form a natural division, so we’ll be going through them one at a time.

This means you can skip around from chapter to chapter if you wish. Once you become familiar with the components that you’re most interested in, you will be able to combine them into the application that you’re dreaming about. So, feel free to invoke a random access approach to reading this book. If you’re more interested in REST APIs than publisher plugins, skip ahead. I promise I won’t be offended.

The three categories of the Google+ platform are social plugins, like the +1 button, RESTful web services, which provide read access to Google+ data, and hangout applications, for writing your own real time collaboration apps. Additionally, the RESTful web services can be used in a couple of ways. You can either access public data directly when you know what you’re looking for, or you can use OAuth 2.0 to access your user’s data on Google+.

Since this architecture is a bit different from other platforms that you may have used, here are a few things that you may recognize and a few things that may be new to you.

Things You May Recognize

If you’ve developed on other social platforms you’re in luck. Many of the technologies and techniques used in the Google+ platform are very similar. This is all thanks to a combination of open standards and best practices that have developed over the past several years.

Social Plugins: If you are a content publisher, or have an existing web application, Google+ plugins provide a simple way to integrate with Google+. They consist of JavaScript and small snippets of HTML markup. Google provides several social plugins including the +1 button, badge, share button, and sign-in button.

The JSON/REST/HTTP Stack: More sophisticated integrations with the Google+ platform rely heavily on JSON messages communicated with RESTful web services over the HTTP protocol. This is how you can programmatically communicate with Google+.

OAuth 2.0: The OAuth 2.0 specification is still in a draft state, but the need for secure access to user data is so acute that it is already being adopted by platforms across the Internet. Google+ has made a commitment to use OAuth 2.0 for APIs going forward.

Things That May Be New to You

As much as developing on Google+ is similar to developing on other modern social platforms, there are a couple of things that may be new to you.

Activity writes require user interaction: This is more of a philosophical difference than a technical one, but it will impact your designs.

A user’s activity is a portal into the lives of people they know. A high-quality stream is very important to Google+. As a result, directly posting to a user’s stream is not supported by the API. Instead, all writes must be triggered directly by the user. This is intended to keep the stream as high quality as possible. In practical terms this means that all writes must be made using the +1 button or the developer preview history API.

Preferred client libraries: RESTful APIs are great in that they provide a language-agnostic way to access data that resides on a remote system. Unfortunately, the specifications can be broadly interpreted, and nuance differences between implementations can make your code complicated.

To ease development in the language of your choice, Google is actively developing preferred client libraries for many popular languages.

If at all possible, use one of these libraries. Everything from the reference documentation to starter projects provided by Google is written using these libraries. In the same vein, all of the sample code is in this book is written using these client libraries.

The recommended client libraries are open source and provided under the favorable terms of the Apache 2.0 license.

Explore the API

Without further ado, it’s time to dive into the API. The easiest way to see the Google+ platform in action is to use the API Explorer. This tool is accessible at https://developers.google.com/apis-explorer/#s/plus/v1/. It provides point-and-click access to most of the APIs that Google offers, including the REST APIs for Google+.

Follow these steps to fetch your public Google+ profile with the REST API.

  1. Navigate to the API Explorer as shown in Figure 1-1. The hash fragment in the URL above should have automatically selected the Google+ API. Near the top of the content pane, you should see the selected API and version: Google+ API v1. Below this is a list of the available methods.

  2. Scanning through the available methods, as shown in Figure 1-2, the plus.people.get method looks like a match. Click it to reveal input fields.

  3. Unfortunately, it requires a userId, which you probably don’t know. The shortcut value me can be used in its place, but since your identity on Google+ is private information, it is protected by OAuth 2.0. You must authorize the API explorer to use it. Click the toggle switch entitled Authorize requests using OAuth 2.0 to initiate this authorization.

  4. An OAuth scope dialog will appear, as shown in Figure 1-3. Check the checkbox for the https://www.googleapis.com/auth/plus.me scope, and click the Authorize button. If this is your first time using the API Explorer with Google+ you must also grant the API Explorer access to your identity on Google+.

  5. The API Explorer now has permission to determine your userId. Specify me for userId and to execute the query, as shown in Figure 1-4.

  6. Upon execution, the request history pane at the bottom of the window displays the API Explorer’s request and the API server’s response, as shown in Figure 1-5. Assuming it was successful, you should see the HTTP headers from request and the full response. This includes a JSON representation of your public Google+ profile.

Congratulations! With a just few clicks you’re already using the Google+ platform.

Over the course of these steps you witnessed many important features of the REST APIs provided by the Google+ platform. You danced the OAuth 2.0 dance to grant the API Explorer access to your identity on Google+, and you observed it fetching your Google+ profile.

The API Explorer listing the methods of Google+ API v1

Figure 1-1. The API Explorer listing the methods of Google+ API v1

The API Explorer panel for crafting a people.get request

Figure 1-2. The API Explorer panel for crafting a people.get request

The API Explorer’s OAuth 2.0 scope selection dialog for the Google+ API

Figure 1-3. The API Explorer’s OAuth 2.0 scope selection dialog for the Google+ API

A completed people.get request form on the API Explorer

Figure 1-4. A completed people.get request form on the API Explorer

A typical response to a successful people.get request

Figure 1-5. A typical response to a successful people.get request

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required