I am having a hard time with facebook's SDK documentation. I downloaded the SDK from Github and added it into my PHP project.
Here is the file system:
├── Facebook
│ ├── FacebookAuthorizationException.php
│ ├── FacebookCanvasLoginHelper.php
│ ├── FacebookClientException.php
│ ├── FacebookJavaScriptLoginHelper.php
│ ├── FacebookOtherException.php
│ ├── FacebookPermissionException.php
│ ├── FacebookRedirectLoginHelper.php
│ ├── FacebookRequest.php
│ ├── FacebookRequestException.php
│ ├── FacebookResponse.php
│ ├── FacebookSDKException.php
│ ├── FacebookServerException.php
│ ├── FacebookSession.php
│ ├── FacebookThrottleException.php
│ ├── GraphLocation.php
│ ├── GraphObject.php
│ ├── GraphSessionInfo.php
│ ├── GraphUser.php
│ └── fb_ca_chain_bundle.crt
└── test.php
here is my code so far:
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication('*******','******');
$helper = new FacebookRedirectLoginHelper('http://isgeek.eu/fb/FaRepost/return.php');
$loginUrl = $helper->getLoginUrl();
// Use the login url on a link or button to redirect to Facebook for authentication
I get this error
Fatal error: Class 'Facebook\FacebookSession' not found in /homepages/2/d184071366/htdocs/isgeek/fb/FaRepost/test.php on line 9
At updated my PHP version, so the issue does not comme from here. It seems like the PHP files are not found. I read this question (Facebook SDK v4 for PHP Minimal Example) but it does not help.
Where does this comme from?
You should be careful with all the paths!
I cannot see "autoload.php" in your file system. In my case I put the content of PHP SDK in the directory "fb", and use the paths (added DIR . into the "define" line in comparison with the example of https://developers.facebook.com/docs/php/gettingstarted/4.0.0)
It helped to avoid that kind of the error.
No need to use
require
orinclude
. I solved it. Just use following line at the top of your script:and you are done.
-just add this code .it works. enter your app_id and app_secret of your facebookAPP
Rename all Facebook files and directories to lower case. Auto-loading on *nix automatically lowercases all files names.
This code worked for me
use packaname\classname
.use
is used to load dynamic classes usingspl_autoload_register
autoload.php
orautoload_fb.php
facebook-php-sdk-v4-4.0-dev/
.FACEBOOK_SDK_V4_SRC_DIR
i.e. path of the facebook libraryNote: I have copied
/var/www/stack/24006673/facebook-php-sdk-v4-4.0-dev/src/Facebook
directory and/var/www/stack/24006673/facebook-php-sdk-v4-4.0-dev/autoload.php
file in root directory/var/www/stack/24006673/