Google API Connector

Experimental project

This is a sandbox project, which contains experimental code for developer use only.

The Google API Communicator aims to be a universal API connector utility module for connecting Drupal modules with Google by oAuth2. It does little on its own, but provides a Google_Client object as obtained from the Google APIs Client Library for PHP library, for usage by other modules. This Google_Client combined with the library can be used to make request against the Google APIs.

Features

  • Integration with Composer Manager (preferred) and Libraries API (alternative) to load the Google APIs Client Library for PHP.
  • google_api_communicator_get_client() for fetching the Google_Client object from your module.
  • hook_google_api_communicator_scopes() for defining all scopes your implementation requires.

Installation

If you install this module via Drush and you have Composer Manager installed, you should be good. Otherwise read the Composer Manager documentation for manual installation.
When you want to use the libraries modules, download the Google APIs Client Library from the above link and upload it in sites/all/libraries/google-api-php-client (so that the readme file is at sites/all/libraries/google-api-php-client/README.md).

This module provides a settings form for site-wide connections on behalf of the organization or company. (Per-user connections might be added later if there is need for them.) One can establish a connection by visiting admin/config/services/google_api_communicator.

Module developer information

By utilizing hook_google_api_communicator_scopes() and google_api_communicator_get_client() a module can register its required scopes, have the user authenticate and perform requests against the APIs.

Example integration for Drive:

/**
 * Implements hook_google_api_communicator_scopes(),
 */
function mymodule_google_api_communicator_scopes() {
  return array(
    Google_Service_Drive::DRIVE_METADATA_READONLY,
  );
}

/** 
 * Obtains a file list from Drive.
 */
function list_files() {
  $uid = 7;
  // $uid = NULL // Use this to load the file list of the 'site' user.
  $client = google_api_communicator_get_client($uid);
  $drive_service = new Google_Service_Drive($client);
  $files_list = $drive_service->files->listFiles(array())->getItems();
  return $files_list;

Similar modules

There are two other modules providing seemingly similar functionality, but they are different in these aspects.

GAuth

Gauth provides a similar oAuth setup, but registers the scopes and services internally. This is less flexible (you will either have all scopes of a service or none), not compatible with older APIs such as Picasa's, and more sensitive to becoming outdated when Google changes the APIs. But it does offer the option to have multiple Drupal users register for a service.

Google API

This is a wrapper for the google_api_php_client library, but does not come with authentication options.

Supporting organizations: 

Project information