Hide
Google Prediction API

Samples and Libraries

The Google Prediction API is built on HTTP and JSON, so any standard HTTP client can send requests to it and parse the responses.

However, the Google APIs client libraries provide better language integration, improved security, and support for making calls that require user authorization. The client libraries are available in a number of programming languages; by using them you can avoid the need to manually set up HTTP requests and parse the responses.

Go


Get the latest Google Prediction API client library for Go (alpha).

Read the client library's developer's guide.

Java

This page contains information about getting started with the Prediction API using the Google API Client Library for Java. In addition, you may be interested in the following documentation:

Sample

The prediction-cmdline-sample may help you get started using the client library.

Add Library to Your Project

Select your build environment (Maven or Gradle) from the following tabs, or download a zip file containing all of the jars you need:

Download

Download the Prediction API v1.6 Client Library for Java.

See the prediction/readme.html file for details on:

  • What the zip file contains.
  • Which dependent jars are needed for each application type (web, installed, or Android application).

The libs folder contains all the of the globally applicable dependencies you might need across all application types.

JavaScript


Read the client library's developer's guide.

.NET

This page contains information about getting started with the Prediction API using the Google APIs Client Library for .NET. In addition, you may be interested in the following documentation:

Downloading the library

Install a NuGet package from those available at Google.Apis.prediction.

Node.js


Get the latest Google Prediction API client library for Node.js.

Read the client library's developer's guide.

Objective-C


Get the latest Google Prediction API client library for Objective-C.

Read the client library's developer's guide.

PHP


Get the latest Google Prediction API client library for PHP (beta).

Read the client library's developer's guide.

Python

This page contains information about getting started with the Prediction API using the Google APIs Client Library for Python. In addition, you may be interested in the following documentation:

System requirements

Installing the client library

You can either use a package manager or download and install the Python client library manually:

Managed installation

Use pip or setuptools to manage your installation (you might need to run sudo first):

  • pip (preferred):
    $ pip install --upgrade google-api-python-client
          
  • Setuptools: Use the easy_install tool included in the setuptools package:
    $ easy_install --upgrade google-api-python-client
    

Manual installation

Download arrow Download the latest client library for Python, unpack the code, and run python setup.py install

App Engine

Because Google App Engine requires that all of the source files for a library must be present in your App Engine project, there is a special installation procedure for App Engine. To install the library and all of its dependencies in an App Engine project, download the file named google-api-python-client-gae-N.M.zip from the list of downloads, where N.M is the version number of the latest release. Unzip that file into your project. For example:

$ cd myproject
$ unzip google-api-python-client-gae-1.2.zip

Ruby

This page contains information about getting started with the Prediction API using the Google APIs Client Library for Ruby. In addition, you may be interested in the following documentation:

Sample

The prediction sample may help you get started using the client library.

Installing the google-api-client gem

If you haven't installed the Google APIs Client Library for Ruby before, open a terminal and install using RubyGems:

$ gem install google-api-client

If you already have the gem installed and would simply like to update to the latest version:

$ gem update -y google-api-client

Depending on your system, you may need to prepend these commands with sudo.

Getting started with the Google APIs Client Library for Ruby

Be sure to check our extensive Getting started guide for a quick overview of how to make your first request.

Other ways to access the Google Prediction API

The table below lists some other convenient ways to access the Google Prediction API.

Access method Description
APIs Explorer An interactive tool that lets you easily try out Google APIs right from your browser.
Google Plugin for Eclipse A plugin that makes it easier to use Google APIs in Eclipse.

Here are additional ways to access the Prediction API:

Access Method Description
Apps Script A JavaScript cloud scripting language that makes it easy to automate tasks across Google products and third party services. See the sample Google Spreadsheet that uses Apps Script to call the Prediction API for more details.
Google Prediction Client Library for R A client library that lets you use the Google Prediction API with the R language.

Sample: Calling Prediction API from App Engine

Quick example

A quick example of calling Prediction API from App Engine.

Full sample application

Google offers a featured sample application that includes all of the code required to exercise the Google Prediction API in a scalable web service hosted on Google App Engine. The featured application is called "Try-Prediction" and is available in Java and Python. Included in the featured app is a complete implementation of server-side shared OAuth 2.0 authentication/authorization credentials.

The source code and documentation for this application are available at Try Prediction.

You can also experiment with "Try Prediction" interactively at http://try-prediction.appspot.com.

Access Prediction with App Engine service accounts

Use a pre-trained, publicly hosted predictive model and train your own predictive model, using an App Engine Service Account for easy authentication. Building on the Python version of the App Engine Guestbook application from the App Engine Getting Started Guide, which allows users to post messages, you can add the Prediction API to classify each message as having a positive or negative sentiment, first using a publicly hosted model and then, with a language identifier (for English, Spanish, or French), using a model that you will train using sample data.

For more information, read the article on accessing App Engine service accounts with the Prediction API.