1

I have added a library to the libraries folder. I have the Libraries API module installed and I wrote this code:

function my_module_libraries_info() {
  $libraries['google-api-php-client'] = array(
    'name' => 'Google Api PHP Client',
    'path' => 'src/Google',
    'vendor_url' => 'https://github.com/google/google-api-php-client',
    'download_url'=> 'https://github.com/google/google-api-php-client',
    'files' => array(
      'php' => array(
        'Client.php',
        'Service.php',
      ),
    ),
  );
  return $libraries;
}

and the code to call it

$library =libraries_load('google-api-php-client');
dpm($library);

This dpm did give me a library array, so it looked like it was ok. But then I tried

$client = new Google_Client();

and I got an error:

PHP Fatal error:  require(): Failed opening required 'http://[site-name-here]/sites/all/libraries/google-api-php-client/src/Google/Client.php' 

When I tried this

 global $base_root;
  require $base_root . '/'. libraries_get_path('google-api-php-client') . '/src/Google/Client.php';

I got the same error message. I checked and saw tat the files were still there. What is going wrong?

0

Clearing the cache might help. I had tried to use libraries_flush_caches but that didn't seem to work. General CC did though - that will ensure libraries_load detects and loads the files you put in your files array.

Also, for this library (at least composer version "google/apiclient": "1.0.*@beta") , you want to put 'autoload.php' in your files array - it'll do what it sounds like, auto-load all the classes you want to use instead of you manually having to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.