I'm trying to integrate the new Facebook SDK4 for PHP in my Drupal 7.34 website, where I have successfully installed it using the libraries API but after that instead of the code execution I'm getting this error:
Fatal error: Class 'Facebook\FacebookSession' not found in mymodule.module on line 122
Where on line no 122, I've used this:
FacebookSession::setDefaultApplication('my_app_id', 'secret'); Line - 122
$session = FacebookSession::newAppSession(); Line - 123
$request = new FacebookRequest($session, 'GET', '/' . 'my_fb_page_id' . '/feed'); Line - 124
This use to get work perfectly when I was intergrating it in this way:
require (drupal_get_path('module', 'social_feeds') . '/facebook-php-sdk-v4-master/src/Facebook/autoload.php');
Below are the steps that I've used for integrating the Facebook SDK with libraries:
In mymodule.module
/**
* The minimum version of Facebook SDK required.
*/
define('MYMODULE_MIN_PLUGIN_VERSION', '4.0');
/**
* Implementation of hook_libraries_info().
*/
function mymodule_libraries_info() {
return array(
'mymodule' => array(
'name' => 'PHP SDK for Facebook APIs',
'vendor url' => 'http://developers.facebook.com/',
'download url' => 'https://github.com/facebook/facebook-php-sdk-v4/archive/master.zip',
'xautoload' => function($adapter) {
$adapter->add('Facebook', 'src');
},
'version arguments' => array(
'file' => 'facebook-php-sdk-v4-master/src/Facebook/Facebook.php',
'pattern' => "/const VERSION = '([\d.]*(?!-dev$))/",
'lines' => 60,
),
'files' => array(
'php' => array(
'facebook-php-sdk-v4-master/src/Facebook/autoload.php',
),
),
),
);
}
and in mymodule.install
file I've mentioned this:
/**
* Implements hook_requirements().
*/
function mymodule_requirements($phase) {
$requirements = array();
// Ensure translations don't break at install time
$t = get_t();
$library = libraries_detect('mymodule');
$error_type = isset($library['error']) ? drupal_ucfirst($library['error']) : '';
$error_message = isset($library['error message']) ? $library['error message'] : '';
if (empty($library['installed'])) {
$requirements['mymodule'] = array(
'title' => $t('MyModule'),
'value' => $t('@e: At least @a', array('@e' => $error_type, '@a' => MYMODULE_MIN_PLUGIN_VERSION)),
'severity' => REQUIREMENT_ERROR,
'description' => $t('!error You need to download the !mymodule,
place the mymodule directory in the %path directory on your server
and extract the archive
.', array(
'!error' => $error_message,
'!mymodule' => l($t('MyModule'),
$library['download url']
),
'%path' => 'sites/all/libraries')),
);
}
elseif (version_compare($library['version'], MYMODULE_MIN_PLUGIN_VERSION, '>=')) {
$requirements['mymodule'] = array(
'title' => $t('MyModule'),
'severity' => REQUIREMENT_OK,
'value' => 'v' . $library['version'] . ' installed',
);
}
else {
$requirements['mymodule'] = array(
'title' => $t('MyModule'),
'value' => $t('At least @a', array('@a' => MYMODULE_MIN_PLUGIN_VERSION)),
'severity' => REQUIREMENT_ERROR,
'description' => $t('You need to download a later version of the
!mymodule and replace the old version located in the %path directory
on your server.', array(
'!mymodule' => l($t('MyModule'),
$library['download url']),
'%path' => $library['library path'])),
);
}
return $requirements;
}
I have also got this in my admin/reports/status
MyModule v4.1.0 installed
Which means I have integrated the Facebook SDK correctly.
The only issue is with this error "Fatal error: Class 'Facebook\FacebookSession' not found in"
where I think my xautoload implementation is incorrect, but I your need suggestion over this.
Thanks.
Comments
Comment #1
leewoodman CreditAttribution: leewoodman commentedSame error here but i am implementing it slightly differently:
Comment #2
donquixote CreditAttribution: donquixote commentedhttps://www.drupal.org/node/1976234
"Always call libraries_load($library_name)"
"Libraries + xautoload works without libraries_load() for BC reasons, but don't count on that!"
Are you calling libraries_load()?
I'm not sure this is the reason for your problem, there could be something else going wrong. Just mentioning it as a first step.
Comment #3
donquixote CreditAttribution: donquixote commentedWhy is your library named "mymodule" ? This seems wrong.
This suggests that the root folder of the library, as seen by Libraries API, is one level up from where it should be.
So, you probably have
sites/all/libraries/mymodule/facebook-php-sdk-v4-master/src/Facebook/Facebook.php
and sites/all/libraries/mymodule is the root folder for this library, as seen by Libraries API.
This means in the xautoload setup you would need
But the better solution would be to fix the folder setup for the library.
Comment #4
donquixote CreditAttribution: donquixote commented@leewoodman:
You don't say how you integrate your module / library with xautoload. So I can't really help you.
Comment #5
Rishi KulshreshthaThis worked like a charm, thanks for your help @donquixote.