How do I load a library using xautoload and libraries? I am trying to load the facebook SDK (drupal 7) but I am getting the error 

Error: Class 'Facebook\Facebook' not found in 
FbPageSyncProcessSubmission::fbpagesync_facebook_sdk_initialize() (


My method

First download the facebook api  Facebook API as recommended

cd web/sites/all/libraries
mkdir fbpagesync
composer require facebook/graph-sdk


Install xautoload

drush dl xautoload &amp;&amp; drush en -y xautoload

In my custom module declare the library

function fbpagesync_libraries_info() {
  return [
    'fbpagesync' =&gt; [
      'name' =&gt; 'PHP SDK for Facebook APIs',
      'vendor url' =&gt; 'http://developers.facebook.com/',
      'download url' =&gt; 'https://github.com/facebook/php-graph-sdk/master.zip',
      'xautoload' =&gt; function ($adapter) {
       $adapter-&gt;composerJson('composer.json');
     },
      'path' =&gt; 'vendor/facebook/graph-sdk/src/Facebook',
      'version arguments' =&gt; [
      'file' =&gt; 'vendor/facebook/graph-sdk/src/Facebook/Facebook.php',
      'pattern' =&gt; "/const VERSION = '([\d.]*(?!-dev$))/",
      'lines' =&gt; 60,
    ],
  ],
  ];
}


It looks OK in libraries_load/libraries_detect

array (
 'name' =&gt; 'PHP SDK for Facebook APIs',
 'vendor url' =&gt; 'http://developers.facebook.com/',
 'download url' =&gt; 'https://github.com/facebook/php-graph-sdk/master.zip',
 'xautoload' =&gt; 
   Drupal\xautoload\Libraries\SerializableClosureWrapper::__set_state(array(
   'closure' =&gt; 
   Closure::__set_state(array(
  )),
 'moduleName' =&gt; 'fbpagesync',
 'libraryName' =&gt; 'fbpagesync',
)),
'path' =&gt; 'vendor/facebook/graph-sdk/src/Facebook',
'version arguments' =&gt; 
  array (
  'file' =&gt; 'vendor/facebook/graph-sdk/src/Facebook/Facebook.php',
  'pattern' =&gt; '/const VERSION = \'([\\d.]*(?!-dev$))/',
  'lines' =&gt; 60,
 ),
'info type' =&gt; 'module',
'module' =&gt; 'fbpagesync',
'machine name' =&gt; 'fbpagesync',
'download file url' =&gt; '',
'library path' =&gt; 'sites/all/libraries/fbpagesync',
'version callback' =&gt; 'libraries_get_version',
'files' =&gt; 
array (
),
'dependencies' =&gt; 
array (
),
'versions' =&gt; 
array (
),
'integration files' =&gt; 
array (
),
'callbacks' =&gt; 
array (
  'info' =&gt; 
array (
  0 =&gt; 'libraries_prepare_files',
),
'pre-detect' =&gt; 
array (
),
'post-detect' =&gt; 
array (
  0 =&gt; 'libraries_detect_dependencies',
),
'pre-dependencies-load' =&gt; 
array (
),
'pre-load' =&gt; 
array (
),
'post-load' =&gt; 
array (
),
),
'post-load integration files' =&gt; false,
'installed' =&gt; true,
'version' =&gt; '5.6.3',
'loaded' =&gt; 0,
)


The calling code is 

use Facebook\Facebook;

...

public static function fbpagesync_facebook_sdk_initialize($reset = FALSE) {
 $settings = variable_get('fbpagesync_settings', []);      
 $facebookInit = new Facebook([
    'app_id' =&gt; $settings['app_id'],
    'app_secret' =&gt; $settings['app_secret'],
    'default_graph_version' =&gt; 'v2.2',
  ]);   
}
It was calling the wrong composer.json. Facebook api has it's own.

The fix is

$adapter-&gt;composerJson('vendor/facebook/graph-sdk/composer.json');