Hi there,

I have been searching for a D7 module that makes the Google API PHP client available, preferably with the libraries module. I have found the googleapilibs module but this only provides access to the AJAX libraries and is outdated.

So i have been looking for a way to implement this myself and eventually share a full module for others to use. I am trying to figure out what would be the best approach for this. I hope you can find some time to help me with this.

Background information

The Google API PHP library makes it possible to interact with Google Services such as Analytics, Calendar, Fusion Tables, Maps, YouTube and many more. There are multiple client libraries available for .NET, Java, Python Ruby and obviously PHP. The Client library is a package containing the Google_Client.php and a seperate code file for each service, for instance 'Google_YouTubeService.php'. So when i want to use a specific service i need both the Client and the Service PHP file loaded.

The PHP Client library can be downloaded here : http://code.google.com/p/google-api-php-client/

The directory structure of the library is as follows:

Main Google Client PHP file.

Services PHP files.

Option 1: Full package

My first idea was to put everything in one hook_libraries_info() implementation and create a seperate $libraries['name'] element for each service. Here i get stuck with array key needing to be the folder name in sites/all/libraries which i cannot re-use. Creating a $libraries['youtube-data-api'] would mean i have to create a copy of the full API in sites/all/libraries. Then i checked to documentation and saw the "variants" option. I could create a $libraries['google-api-php-client'] array which points to the Google_Client.php and create variants for each service. This would probably work but it feels as if i am using variants all wrong. So the option for a full package pretty much ends there. Obviously i can create $libraries['google-api-php-client'] and add all PHP files to the files > php array, but that would mean the PHP files for all services would be loaded all the time.

Option 2: Module with submodules

My second option would be creating a 'master' module for the Google API client and a seperate module for each service. I could then use the 'integration files' array to add the PHP files for specific services. I'm curious however if this would load files within the modules directory or if this would load additional files within the library. Since the library also contains a few configuration files and tools (such as Oath2 implementation) i don't want to copy files into a seperate module directory. Also i wonder what will happen when i add integration files for modules that are disabled.

I hope you can shed your light on this and give me some tips on how to tackle this.


tstoeckler’s picture

Title:Proper implementation for Google Google API PHP Client» Allow a single download to contain multiple libraries
Version:7.x-2.1» 7.x-3.x-dev
Category:support» feature

Hi, thanks for the question.

So 'integration files' are for module-provided files, so they don't make sense in this case.

'variants' are for different variations of the same code, usually used for 'minified' vs. 'source' for JS libraries. So your notion that you're using them wrong was sort of correct.

So really what you want is to declare a library that bundles several libraries in one project/download. There currently is no support for this in Libraries API, but it seems we should add that.

So changing this into a feature request.

I'm not yet quite sure how this would work behind the scenes but from an implementation perspective,
something like this should work, right?:

// In the docs for hook_libraries_info()
*   - directory name: (optional) The name of the directory this library is contained in. This defaults
*     to the machine-readable name of the library and should only be set in-case a single download
*     of a an external project contains multiple libraries. In that case each library can be declared
*     separately, and this key can be set to the project name so that all libraries are found in the same
*     directory.
tstoeckler’s picture

Hmm... thinking out loud: I wonder if we could solve this with derivatives in D8.

tstoeckler’s picture

Issue summary:View changes

added info about Google API Client PHP library.