简体   繁体   中英

Posting message using Facebook SDK for PHP

Hello I'm working with a PHP code using Facebook SDK to post a message on a facbook page which I am the admin it's ok when I work in localhost but when I hosted my page on a web server it gives me the following error:

 Fatal error: Class 'Facebook\FacebookSession' not found in /var/www/simo/index.php on line 48

The lines of code that cause problem:

use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookSession;
use Facebook\FacebookRequest;

require "vendor/autoload.php"; 
session_start();
$appId='358738637667835';
$appSecret='92841aa4b36c9c37a4d779e801db3d6f';
FacebookSession::setDefaultApplication($appId,$appSecret);//(line 48)

The thing that should be noted is that the version of my server's PHP is “PHP 5.4.39” that normally understands the instruction "use".

Thank you for giving me a solution or a suggestion.

This problem happens as a result of incorrect paths. If you downloaded the PHP SDK , make sure it contains a file called "autoload.php", then add the following line

require __DIR__ . '/facebook-php-sdk/autoload.php';

before the "use statement"

use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookSession;

the autoload.php will fix all paths and do the mapping for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM